class MetalArchives::Artist

Represents a single performer (but not a solo artist)

Attributes

aliases[R]

Returns Array of String

Raises
biography[R]

Returns raw HTML String

Raises
cause_of_death[R]

Returns String

Raises
country[R]

Returns ISO3166::Country

Raises
date_of_birth[R]

Returns NilDate

Raises
date_of_death[R]

Returns NilDate

Raises
gender[R]

Returns Symbol, either :male or :female

Raises
id[R]

Returns Integer

location[R]

Returns String

Raises
name[R]

Returns String

Raises
photo[R]

Returns URI (rewritten if config option was enabled)

Raises
trivia[R]

Returns raw HTML String

Raises

Protected Class Methods

all() click to toggle source

Get all artists

Returns Collection of Artist

Raises
# File lib/metal_archives/models/artist.rb, line 342
def all
  search ''
end
find(id) click to toggle source

Find by ID

Returns Artist, even when ID is invalid (because the data is lazily fetched)

id

Integer

# File lib/metal_archives/models/artist.rb, line 205
def find(id)
  return cache[id] if cache.include? id

  Artist.new :id => id
end
find!(id) click to toggle source

Find by ID (no lazy loading)

Returns Artist

Raises
id

Integer

# File lib/metal_archives/models/artist.rb, line 224
def find!(id)
  obj = find id
  obj.load! if obj && !obj.loaded?

  obj
end
find_by(query) click to toggle source

Find by attributes

Returns Artist or nil when no results

Raises
query

Hash containing one or more of the following keys:

  • :name: String

# File lib/metal_archives/models/artist.rb, line 245
def find_by(query)
  raise MetalArchives::Errors::ArgumentError unless query.include? :name

  url = "#{MetalArchives.config.default_endpoint}search/ajax-artist-search/"
  params = Parsers::Artist.map_params query

  response = HTTPClient.get url, params
  json = JSON.parse response.body

  return nil if json['aaData'].empty?

  data = json['aaData'].first
  id = Nokogiri::HTML(data.first).xpath('//a/@href').first.value.delete('\').split('/').last.gsub(/\D/, '').to_i

  find id
end
find_by!(query) click to toggle source

Find by attributes (no lazy loading)

Returns Artist or nil when no results

Raises
query

Hash containing one or more of the following keys:

  • :name: String

# File lib/metal_archives/models/artist.rb, line 277
def find_by!(query)
  obj = find_by query
  obj.load! if obj && !obj.loaded?

  obj
end