Class: BrainzReleases::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/brainz_releases/release.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Release

Returns a new instance of Release.



6
7
8
# File 'lib/brainz_releases/release.rb', line 6

def initialize(*args, &block)
  self.instance_eval(&block) if block
end

Instance Attribute Details

#artist_mbidObject

Returns the value of attribute artist_mbid.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def artist_mbid
  @artist_mbid
end

#artist_nameObject

Returns the value of attribute artist_name.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def artist_name
  @artist_name
end

#countryObject

Returns the value of attribute country.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def country
  @country
end

#date_availableObject

Returns the value of attribute date_available.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def date_available
  @date_available
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def format
  @format
end

#labelObject

Returns the value of attribute label.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def label
  @label
end

#mbidObject

Returns the value of attribute mbid.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def mbid
  @mbid
end

#release_typeObject

Returns the value of attribute release_type.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def release_type
  @release_type
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def title
  @title
end

#track_countObject

Returns the value of attribute track_count.



4
5
6
# File 'lib/brainz_releases/release.rb', line 4

def track_count
  @track_count
end

Class Method Details

.build_from_node(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/brainz_releases/release.rb', line 10

def self.build_from_node(node)
  Release.new do |release|
    release.mbid = node["id"]
    release.artist_name = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:artist-credit/xmlns:name-credit/xmlns:artist/xmlns:name").first.content rescue nil
    release.artist_mbid = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:artist-credit/xmlns:name-credit/xmlns:artist").first['id']
    release.title = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:title").first.content rescue nil
    release.release_type = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:release-group").first['type']
    release.date_available = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:date").first.content rescue nil
    release.track_count = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:medium-list/xmlns:track-count").first.content rescue nil
    release.format = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:medium-list/xmlns:medium/xmlns:format").first.content rescue nil
    release.label = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:label-info-list/xmlns:label-info/xmlns:label/xmlns:name").first.content rescue nil
    release.country = node.xpath("//xmlns:release[@id='#{release.mbid}']/xmlns:country").first.content rescue nil
  end
end

Instance Method Details

#attributesObject

Returns a hash of all the attributes with their names as keys and the values of the attributes as values.



26
27
28
# File 'lib/brainz_releases/release.rb', line 26

def attributes
  Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] }]
end