Class: MetalArchives::Release
- Defined in:
- lib/metal_archives/models/release.rb
Overview
Represents a release
Class Method Summary collapse
-
.all ⇒ Object
Get all releases.
-
.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(title) ⇒ Object
Search by title, resolves to rdoc-ref:Release.search_by (:title => title).
-
.search_by(query) ⇒ Object
Search by attributes.
Instance Method Summary collapse
-
#band ⇒ Object
:attr_reader: band.
-
#catalog_id ⇒ Object
:attr_reader_: catalog_id.
-
#date_released ⇒ Object
:attr_reader: date_released.
-
#format ⇒ Object
:attr_reader: format.
-
#id ⇒ Object
:attr_reader: id.
-
#limitation ⇒ Object
:attr_reader: limitation.
-
#notes ⇒ Object
:attr_reader: notes.
-
#title ⇒ Object
:attr_reader: title.
-
#type ⇒ Object
:attr_reader: type.
-
#version_description ⇒ Object
:attr_reader_: version_description.
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 releases
Returns rdoc-ref:Collection of rdoc-ref:Release
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
353 354 355 |
# File 'lib/metal_archives/models/release.rb', line 353 def all search "" end |
.find(id) ⇒ Object
Find by ID
Returns rdoc-ref:Release, even when ID is invalid (because the data is lazily fetched)
[+id+]
Integer
150 151 152 153 154 |
# File 'lib/metal_archives/models/release.rb', line 150 def find(id) return MetalArchives.cache[cache(id)] if MetalArchives.cache.include? cache(id) Release.new id: id end |
.find!(id) ⇒ Object
Find by ID (no lazy loading)
Returns 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)
- rdoc-ref:MetalArchives::Errors::ParserError when parsing failed. Please report this error.
[+id+]
Integer
169 170 171 172 173 174 |
# File 'lib/metal_archives/models/release.rb', line 169 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:Release 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:
- :band_name: String
- :title: String
- :from_year: Integer
- :from_month: Integer
- :to_year: Integer
- :to_month: Integer
- :country: ISO3166::Country or Array of ISO3166::Country
- :location: String
- :label_name: String
- :indie: Boolean
- :catalog_id: String
- :identifier: String, identifier (barcode, matrix, etc.)
- :recording_info: String, recording information (studio, city, etc.)
- :version_description: String, version description (country, digipak, etc.)
- :notes: String
- :genre: String
- :types: Array of Symbol, see rdoc-ref:Release.type
- :formats: Array of Symbol, see rdoc-ref:Release.format
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/metal_archives/models/release.rb', line 208 def find_by(query) params = Parsers::Release.map_params query response = MetalArchives.http.get "/search/ajax-advanced/searching/albums", params json = JSON.parse response.to_s return nil if json["aaData"].empty? data = json["aaData"].first id = Nokogiri::HTML(data[1]).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:Release 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:
- :band_name: String
- :title: String
- :from_year: Integer
- :from_month: Integer
- :to_year: Integer
- :to_month: Integer
- :country: ISO3166::Country or Array of ISO3166::Country
- :location: String
- :label_name: String
- :indie: Boolean
- :catalog_id: String
- :identifier: String, identifier (barcode, matrix, etc.)
- :recording_info: String, recording information (studio, city, etc.)
- :version_description: String, version description (country, digipak, etc.)
- :notes: String
- :genre: String
- :types: Array of Symbol, see rdoc-ref:Release.type
- :formats: Array of Symbol, see rdoc-ref:Release.format
254 255 256 257 258 259 |
# File 'lib/metal_archives/models/release.rb', line 254 def find_by!(query) obj = find_by query obj.load! if obj && !obj.loaded? obj end |
.search(title) ⇒ Object
Search by title, resolves to rdoc-ref:Release.search_by (:title => title)
Refer to MA's FAQ for search tips.
Returns (possibly empty) Array of rdoc-ref:Release
[Raises]
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400
- rdoc-ref:MetalArchives::Errors::ArgumentError when
titleisn't aString
[+title+]
String
338 339 340 341 342 |
# File 'lib/metal_archives/models/release.rb', line 338 def search(title) raise MetalArchives::Errors::ArgumentError unless title.is_a? String search_by title: title end |
.search_by(query) ⇒ Object
Search by attributes
Refer to MA's FAQ for search tips.
Returns rdoc-ref:Collection of rdoc-ref:Release
[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:
- :band_name: String
- :title: String
- :from_year: Integer
- :from_month: Integer
- :to_year: Integer
- :to_month: Integer
- :country: ISO3166::Country or Array of ISO3166::Country
- :location: String
- :label_name: String
- :indie: Boolean
- :catalog_id: String
- :identifier: String, identifier (barcode, matrix, etc.)
- :recording_info: String, recording information (studio, city, etc.)
- :version_description: String, version description (country, digipak, etc.)
- :notes: String
- :genre: String
- :types: Array of Symbol, see rdoc-ref:Release.type
- :formats: Array of Symbol, see rdoc-ref:Release.format
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/metal_archives/models/release.rb', line 293 def search_by(query) params = Parsers::Release.map_params query l = lambda do @start ||= 0 if @max_items && @start >= @max_items [] else response = MetalArchives.http.get "/search/ajax-advanced/searching/albums", params.merge(iDisplayStart: @start) json = JSON.parse response.to_s @max_items = json["iTotalRecords"] objects = [] json["aaData"].each do |data| # Create Release 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 << Release.find(id) end @start += 200 objects end end MetalArchives::Collection.new l end |
Instance Method Details
#band ⇒ Object
:attr_reader: band
Returns rdoc-ref:MetalArchives::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)
38 |
# File 'lib/metal_archives/models/release.rb', line 38 property :band, type: Band |
#catalog_id ⇒ Object
:attr_reader_: catalog_id
Return 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)
71 |
# File 'lib/metal_archives/models/release.rb', line 71 property :catalog_id |
#date_released ⇒ Object
:attr_reader: date_released
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)
60 |
# File 'lib/metal_archives/models/release.rb', line 60 property :date_released, type: Date |
#format ⇒ Object
:attr_reader: format
Returns :cd, :cassette, :vinyl, :vhs, :dvd, :digital, :blu_ray, :other, :unknown
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
95 |
# File 'lib/metal_archives/models/release.rb', line 95 property :format |
#id ⇒ Object
:attr_reader: id
Returns Integer
16 |
# File 'lib/metal_archives/models/release.rb', line 16 property :id, type: Integer |
#limitation ⇒ Object
:attr_reader: limitation
Returns 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)
106 |
# File 'lib/metal_archives/models/release.rb', line 106 property :limitation |
#notes ⇒ Object
:attr_reader: notes
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)
123 |
# File 'lib/metal_archives/models/release.rb', line 123 property :notes |
#title ⇒ Object
:attr_reader: title
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)
27 |
# File 'lib/metal_archives/models/release.rb', line 27 property :title |
#type ⇒ Object
:attr_reader: type
Returns :full_length, :live, :demo, :single, :ep, :video, :boxed_set, :split, :compilation, :split_video, :collaboration
[Raises]
- rdoc-ref:MetalArchives::Errors::InvalidIDError when no or invalid id
- rdoc-ref:MetalArchives::Errors::APIError when receiving a status code >= 400 (except 404)
49 |
# File 'lib/metal_archives/models/release.rb', line 49 enum :type, values: [:full_length, :live, :demo, :single, :ep, :video, :boxed_set, :split, :compilation, :split_video, :collaboration] |
#version_description ⇒ Object
:attr_reader_: version_description
Return 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)
82 |
# File 'lib/metal_archives/models/release.rb', line 82 property :version_description |