Class: MetalArchives::Band
- Defined in:
- lib/metal_archives/models/band.rb
Overview
Represents an band (person or group)
Class Method Summary collapse
-
.all ⇒ Object
Get all bands.
-
.find(id) ⇒ Object
Find by ID.
-
.find!(id) ⇒ Object
Find by ID (no lazy loading).
-
.find_by(query) ⇒ Object
Find by attributes.
-
.find_by!(query) ⇒ Object
Find by attributes (no lazy loading).
-
.search(name) ⇒ Object
Search by name, resolves to rdoc-ref:Band.search_by (:name => name).
-
.search_by(query) ⇒ Object
Search by attributes.
Instance Method Summary collapse
-
#aliases ⇒ Object
:attr_reader: aliases.
-
#comment ⇒ Object
:attr_reader: comment.
-
#country ⇒ Object
:attr_reader: country.
-
#date_formed ⇒ Object
:attr_reader: date_formed.
-
#genres ⇒ Object
:attr_reader: genres.
-
#id ⇒ Object
:attr_reader: id.
-
#independent ⇒ Object
:attr_reader: independent.
-
#label ⇒ Object
:attr_reader: label.
-
#links ⇒ Object
:attr_reader: links.
-
#location ⇒ Object
:attr_reader: location.
-
#logo ⇒ Object
:attr_reader: logo.
-
#lyrical_themes ⇒ Object
:attr_reader: lyrical_themes.
-
#members ⇒ Object
:attr_reader: members.
-
#name ⇒ Object
:attr_reader: name.
-
#photo ⇒ Object
:attr_reader: photo.
-
#releases ⇒ Object
:attr_reader: releases.
-
#similar ⇒ Object
:attr_reader: similar.
-
#status ⇒ Object
:attr_reader: status.
-
#years_active ⇒ Object
:attr_reader: years_active.
Methods inherited from Base
#==, cache, #cached?, #initialize, #inspect, #load!, #loaded?, properties, #set
Constructor Details
This class inherits a constructor from MetalArchives::Base
Class Method Details
.all ⇒ Object
Get all bands
Returns rdoc-ref:Collection of rdoc-ref:Band
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
461 462 463 |
# File 'lib/metal_archives/models/band.rb', line 461 def all search_by({}) end |
.find(id) ⇒ Object
Find by ID
Returns rdoc-ref:Band, even when ID is invalid (because the data is lazily fetched)
[+id+]
Integer
279 280 281 282 283 |
# File 'lib/metal_archives/models/band.rb', line 279 def find(id) return MetalArchives.cache[cache(id)] if MetalArchives.cache.include? cache(id) Band.new id: id end |
.find!(id) ⇒ Object
Find by ID (no lazy loading)
Returns rdoc-ref:Band
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
[+id+]
Integer
298 299 300 301 302 303 |
# File 'lib/metal_archives/models/band.rb', line 298 def find!(id) obj = find id obj.load! if obj && !obj.loaded? obj end |
.find_by(query) ⇒ Object
Find by attributes
Refer to MA's FAQ for search tips.
Returns rdoc-ref:Band or nil when no results
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
[+query+]
Hash containing one or more of the following keys:
- :name: String
- :exact: Boolean
- :genre: String
- :country: ISO3166::Country
- :year_formation: rdoc-ref:Range containing rdoc-ref:Date
- :comment: String
- :status: see rdoc-ref:Band.status
- :lyrical_themes: String
- :location: String
- :label: rdoc-ref:Label
- :independent: boolean
330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/metal_archives/models/band.rb', line 330 def find_by(query) params = Parsers::Band.map_params query response = MetalArchives.http.get "/search/ajax-advanced/searching/bands", 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!(query) ⇒ Object
Find by attributes (no lazy loading)
Refer to MA's FAQ for search tips.
Returns rdoc-ref:Band or nil when no results
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
[+query+]
Hash containing one or more of the following keys:
- :name: String
- :exact: Boolean
- :genre: String
- :country: ISO3166::Country
- :year_formation: rdoc-ref:Range containing rdoc-ref:Date
- :comment: String
- :status: see rdoc-ref:Band.status
- :lyrical_themes: String
- :location: String
- :label: rdoc-ref:Label
- :independent: boolean
369 370 371 372 373 374 |
# File 'lib/metal_archives/models/band.rb', line 369 def find_by!(query) obj = find_by query obj.load! if obj && !obj.loaded? obj end |
.search(name) ⇒ Object
Search by name, resolves to rdoc-ref:Band.search_by (:name => name)
Refer to MA's FAQ for search tips.
Returns (possibly empty) Array of rdoc-ref:Band
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ArgumentError when
nameisn't aString
[+name+]
String
446 447 448 449 450 |
# File 'lib/metal_archives/models/band.rb', line 446 def search(name) raise MetalArchives::Errors::ArgumentError unless name.is_a? String search_by name: name end |
.search_by(query) ⇒ Object
Search by attributes
Refer to MA's FAQ for search tips.
Returns rdoc-ref:Collection of rdoc-ref:Band
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
[+query+]
Hash containing one or more of the following keys:
- :name: String
- :exact: Boolean
- :genre: String
- :country: ISO3166::Country
- :year_formation: rdoc-ref:Range containing rdoc-ref:Date
- :comment: String
- :status: see rdoc-ref:Band.status
- :lyrical_themes: String
- :location: String
- :label: rdoc-ref:Label
- :independent: boolean
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/metal_archives/models/band.rb', line 401 def search_by(query) params = Parsers::Band.map_params query l = lambda do @start ||= 0 if @max_items && @start >= @max_items [] else response = MetalArchives.http.get "/search/ajax-advanced/searching/bands", params.merge(iDisplayStart: @start) json = JSON.parse response.to_s @max_items = json["iTotalRecords"] objects = [] json["aaData"].each do |data| # Create Band 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 << Band.find(id) end @start += 200 objects end end MetalArchives::Collection.new l end |
Instance Method Details
#aliases ⇒ Object
:attr_reader: aliases
Returns Array of String
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
39 |
# File 'lib/metal_archives/models/band.rb', line 39 property :aliases, multiple: true |
#comment ⇒ Object
:attr_reader: comment
Returns raw HTML String
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
138 |
# File 'lib/metal_archives/models/band.rb', line 138 property :comment |
#country ⇒ Object
:attr_reader: country
Returns ISO3166::Country
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
50 |
# File 'lib/metal_archives/models/band.rb', line 50 property :country, type: ISO3166::Country |
#date_formed ⇒ Object
:attr_reader: date_formed
Returns rdoc-ref:Date
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
72 |
# File 'lib/metal_archives/models/band.rb', line 72 property :date_formed, type: Date |
#genres ⇒ Object
:attr_reader: genres
Returns Array of String
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
94 |
# File 'lib/metal_archives/models/band.rb', line 94 property :genres, multiple: true |
#id ⇒ Object
:attr_reader: id
Returns Integer
17 |
# File 'lib/metal_archives/models/band.rb', line 17 property :id, type: Integer |
#independent ⇒ Object
:attr_reader: independent
Returns boolean
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
127 |
# File 'lib/metal_archives/models/band.rb', line 127 enum :independent, values: [true, false] |
#label ⇒ Object
:attr_reader: label
Returns rdoc-ref:Label
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
116 |
# File 'lib/metal_archives/models/band.rb', line 116 property :label, type: Label |
#links ⇒ Object
:attr_reader: links
Returns Array of Hash containing the following keys
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
[+links+]
- :url: String
- :type: Symbol, either :official or :merchandise
- :title: String
230 |
# File 'lib/metal_archives/models/band.rb', line 230 property :links, multiple: true |
#location ⇒ Object
:attr_reader: location
Returns String
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
61 |
# File 'lib/metal_archives/models/band.rb', line 61 property :location |
#logo ⇒ Object
:attr_reader: logo
Returns URI (rewritten if config option was enabled)
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
203 |
# File 'lib/metal_archives/models/band.rb', line 203 property :logo |
#lyrical_themes ⇒ Object
:attr_reader: lyrical_themes
Returns Array of String
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
105 |
# File 'lib/metal_archives/models/band.rb', line 105 property :lyrical_themes, multiple: true |
#members ⇒ Object
:attr_reader: members
Returns Array of Hash containing the following keys
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
[+members+]
- :artist: rdoc-ref:Artist
- :current: Boolean
- :years_active: Array of rdoc-ref:Range containing Integer
- :role: String
177 |
# File 'lib/metal_archives/models/band.rb', line 177 property :members, type: Artist, multiple: true |
#name ⇒ Object
:attr_reader: name
Returns String
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
28 |
# File 'lib/metal_archives/models/band.rb', line 28 property :name |
#photo ⇒ Object
:attr_reader: photo
Returns URI (rewritten if config option was enabled)
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
214 |
# File 'lib/metal_archives/models/band.rb', line 214 property :photo |
#releases ⇒ Object
:attr_reader: releases
Returns Array of rdoc-ref:Release
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
160 |
# File 'lib/metal_archives/models/band.rb', line 160 property :releases, type: Release, multiple: true |
#similar ⇒ Object
:attr_reader: similar
Returns Array of Hash containing the following keys
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
[+similar+]
- :band: rdoc-ref:Band
- :score: Integer
192 |
# File 'lib/metal_archives/models/band.rb', line 192 property :similar, type: Hash, multiple: true |
#status ⇒ Object
:attr_reader: status
Returns :active, :split_up, :on_hold, :unknown, :changed_name or :disputed
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
149 |
# File 'lib/metal_archives/models/band.rb', line 149 enum :status, values: [:active, :split_up, :on_hold, :unknown, :changed_name, :disputed] |
#years_active ⇒ Object
:attr_reader: years_active
Returns Array of rdoc-ref:Range containing Integer
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
83 |
# File 'lib/metal_archives/models/band.rb', line 83 property :years_active, type: Range, multiple: true |