Class: MusicBrainz::Release
Constant Summary collapse
- @@class_name =
self.name.gsub('MusicBrainz::', "").downcase
Instance Attribute Summary collapse
-
#artists ⇒ Object
Returns the value of attribute artists.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#recordings ⇒ Object
Returns the value of attribute recordings.
-
#release_groups ⇒ Object
Returns the value of attribute release_groups.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #get_release(method, mbid, query) ⇒ Object
-
#get_subquery(subquery) ⇒ Object
TODO Move to Base class, and use it in each subclass.
-
#initialize(mbid, query = []) ⇒ Release
constructor
A new instance of Release.
-
#inspect ⇒ Object
TODO Expand the inspection, and add to base.
Methods inherited from Base
Constructor Details
#initialize(mbid, query = []) ⇒ Release
Returns a new instance of Release.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/musicbrainz/release.rb', line 12 def initialize(mbid, query=[]) acceptable_subqueries=['artists', 'labels', 'recordings', 'release-groups'] if query.kind_of?(Array) query.each do |query| unless acceptable_subqueries.include?(query) raise "#{query} is an unacceptable Sub-query for #{@@class_name.pluralize.upcase}. Please use one of the following:\n#{acceptable_subqueries}" end end else unless acceptable_subqueries.include?(query) raise "#{query} is an unacceptable Sub-query for #{@@class_name.pluralize.upcase}. Please use one of the following:\n#{acceptable_subqueries}" end end unless mbid.is_mbid raise "Unacceptable MBID for #{@@class_name.pluralize.upcase}. Check to make sure you have the correct mbid." end @mbid=mbid if query.present? && query!=[] @query=query.join("+") if query.kind_of?(Array) @query=query if query.kind_of?(String) else return false end @method='release' get_release(@method, @mbid, @query) end |
Instance Attribute Details
#artists ⇒ Object
Returns the value of attribute artists.
6 7 8 |
# File 'lib/musicbrainz/release.rb', line 6 def artists @artists end |
#labels ⇒ Object
Returns the value of attribute labels.
7 8 9 |
# File 'lib/musicbrainz/release.rb', line 7 def labels @labels end |
#raw ⇒ Object
Returns the value of attribute raw.
5 6 7 |
# File 'lib/musicbrainz/release.rb', line 5 def raw @raw end |
#recordings ⇒ Object
Returns the value of attribute recordings.
8 9 10 |
# File 'lib/musicbrainz/release.rb', line 8 def recordings @recordings end |
#release_groups ⇒ Object
Returns the value of attribute release_groups.
9 10 11 |
# File 'lib/musicbrainz/release.rb', line 9 def release_groups @release_groups end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/musicbrainz/release.rb', line 4 def title @title end |
Instance Method Details
#get_release(method, mbid, query) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/musicbrainz/release.rb', line 43 def get_release(method, mbid, query) @raw=self.class.get(method, mbid, query) subquery=query.split("+") if subquery.kind_of?(Array) subquery.each do |q| get_subquery(q) end else get_subquery(subquery) end end |
#get_subquery(subquery) ⇒ Object
TODO Move to Base class, and use it in each subclass. Expand for each usage as needed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/musicbrainz/release.rb', line 57 def get_subquery(subquery) subquery=subquery.gsub("-", "_") subquery_s=subquery.singularize if subquery_s=='artist' list_array=@raw['metadata']["#{@@class_name}"]["#{subquery_s}_credit"]['name_credit']["#{subquery_s}"] elsif subquery_s=='label' list_array=@raw['metadata']["#{@@class_name}"]["#{subquery_s}_info_list"]["#{subquery_s}_info"]["#{subquery_s}"] elsif subquery_s=='release_group' list_array=@raw['metadata']["#{@@class_name}"]["#{subquery_s}"] elsif subquery_s=='recording' list_array=@raw['metadata']["#{@@class_name}"]['medium_list']['medium']['track_list']['track'] end if list_array.kind_of?(Array) sub=Array.new list_array.each do |r| sub<<OpenStruct.new(r) end else sub=OpenStruct.new(list_array) end @artists=sub if subquery=='artists' @labels=sub if subquery=='labels' @recordings=sub if subquery=='recordings' @release_groups=sub if subquery=='release_groups' end |
#inspect ⇒ Object
TODO Expand the inspection, and add to base
84 85 86 |
# File 'lib/musicbrainz/release.rb', line 84 def inspect "#{@@class_name.upcase} identified by:#{@mbid}, Title:#{@title} }" end |