class MetalArchives::Artist
Represents a single performer (but not a solo artist)
Attributes
Returns Array
of String
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns Array
of Hash
containing the following keys
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
bands
-
:band
:Band
-
:active
: Boolean -
:years_active
:Array
of Range containingInteger
-
:role
:String
-
Returns raw HTML String
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns String
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns ISO3166::Country
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns Date
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns Date
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns Symbol
, either :male
or :female
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns Integer
Returns Array
of Hash
containing the following keys
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
links
-
:url
:String
-
:type
:Symbol
, either:official
,:unofficial
or:unlisted_bands
-
:title
:String
-
Returns String
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns String
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns URI
(rewritten if config option was enabled)
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Returns raw HTML String
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404)
Public Class Methods
Deserialize from hash
# File lib/metal_archives/models/artist.rb, line 202 def self.from_h(hash) return unless hash.fetch(:type) == "artist" new(hash.slice(:id, :name, :aliases, :location, :cause_of_death, :gender, :biography, :trivial, :photo, :links, :bands)) .tap { |m| m.country = ISO3166::Country[hash[:country]] } .tap { |m| m.date_of_birth = Date.parse(hash[:date_of_birth]) if hash[:date_of_birth] } .tap { |m| m.date_of_death = Date.parse(hash[:date_of_death]) if hash[:date_of_death] } end
Protected Class Methods
Get all artists
Returns Collection
of Artist
- Raises
-
MetalArchives::Errors::APIError
when receiving a status code >= 400 -
MetalArchives::Errors::ParserError
when parsing failed. Please report this error.
# File lib/metal_archives/models/artist.rb, line 388 def all search "" end
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 253 def find(id) return MetalArchives.cache[cache(id)] if MetalArchives.cache.include? cache(id) Artist.new id: id end
Find by ID (no lazy loading)
Returns Artist
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 (except 404) -
MetalArchives::Errors::ParserError
when parsing failed. Please report this error.
id
-
Integer
# File lib/metal_archives/models/artist.rb, line 272 def find!(id) obj = find id obj.load! if obj && !obj.loaded? obj end
Find by attributes
Returns Artist
or nil when no results
- Raises
-
MetalArchives::Errors::APIError
when receiving a status code >= 400 -
MetalArchives::Errors::ParserError
when parsing failed. Please report this error. -
MetalArchives::Errors::ArgumentError
when query contains no :name key
query
-
Hash containing one or more of the following keys:
-
:name
:String
-
# File lib/metal_archives/models/artist.rb, line 293 def find_by(query) raise MetalArchives::Errors::ArgumentError unless query.include? :name params = Parsers::Artist.map_params query response = MetalArchives.http.get "/search/ajax-artist-search/", params json = JSON.parse response.to_s 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 attributes (no lazy loading)
Returns Artist
or nil when no results
- Raises
-
MetalArchives::Errors::InvalidIDError
when no or invalid id -
MetalArchives::Errors::APIError
when receiving a status code >= 400 -
MetalArchives::Errors::ParserError
when parsing failed. Please report this error. -
MetalArchives::Errors::ArgumentError
when query contains no :name key
query
-
Hash containing one or more of the following keys:
-
:name
:String
-
# File lib/metal_archives/models/artist.rb, line 324 def find_by!(query) obj = find_by query obj.load! if obj && !obj.loaded? obj end
Search by name
Returns Collection
of Artist
- Raises
-
MetalArchives::Errors::APIError
when receiving a status code >= 400 -
MetalArchives::Errors::ParserError
when parsing failed. Please report this error. -
MetalArchives::Errors::ArgumentError
whenname
isn't aString
name
-
String
# File lib/metal_archives/models/artist.rb, line 344 def search(name) raise MetalArchives::Errors::ArgumentError unless name.is_a? String query = { name: name } params = Parsers::Artist.map_params query l = lambda do @start ||= 0 if @max_items && @start >= @max_items [] else response = MetalArchives.http.get "/search/ajax-artist-search/", params.merge(iDisplayStart: @start) json = JSON.parse response.to_s @max_items = json["iTotalRecords"] objects = [] json["aaData"].each do |data| # Create Artist object for every ID in the results list id = Nokogiri::HTML(data.first).xpath("//a/@href").first.value.delete('\\').split("/").last.gsub(/\D/, "").to_i objects << Artist.find(id) end @start += 200 objects end end MetalArchives::Collection.new l end
Public Instance Methods
Serialize to hash
# File lib/metal_archives/models/artist.rb, line 179 def to_h { type: "artist", id: id, name: name, aliases: aliases || [], country: country&.alpha3, location: location, date_of_birth: date_of_birth&.iso8601, date_of_death: date_of_death&.iso8601, cause_of_death: cause_of_death, gender: gender, biography: biography, trivia: trivia, photo: photo, links: links || [], bands: bands || [], } end