Class: MusicBrainz::Artist

Inherits:
Base
  • Object
show all
Defined in:
lib/musicbrainz/artist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

get, get_query_path

Constructor Details

#initialize(mbid, query = []) ⇒ Artist

Returns a new instance of Artist.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/musicbrainz/artist.rb', line 10

def initialize(mbid, query=[])
  #Valid sub-queries: artists, labels, recordings, release-groups
  @mbid=mbid.is_mbid ? mbid : false
  if query.present? && query!=[]
    @query=query.join("+")
  else
    @query='releases'
  end
  @method='artist'
  get_request(@method, @mbid, @query)
end

Instance Attribute Details

#artist_infoObject

Returns the value of attribute artist_info.



6
7
8
# File 'lib/musicbrainz/artist.rb', line 6

def artist_info
  @artist_info
end

#metadataObject

Returns the value of attribute metadata.



3
4
5
# File 'lib/musicbrainz/artist.rb', line 3

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/musicbrainz/artist.rb', line 4

def name
  @name
end

#release_groupsObject

Returns the value of attribute release_groups.



7
8
9
# File 'lib/musicbrainz/artist.rb', line 7

def release_groups
  @release_groups
end

#releasesObject

Returns the value of attribute releases.



5
6
7
# File 'lib/musicbrainz/artist.rb', line 5

def releases
  @releases
end

#worksObject

Returns the value of attribute works.



8
9
10
# File 'lib/musicbrainz/artist.rb', line 8

def works
  @works
end

Instance Method Details

#get_infoObject



31
32
33
# File 'lib/musicbrainz/artist.rb', line 31

def get_info
  @artist_info={:type => @metadata['artist']['type'], :mbid => @metadata['artist']['id']}
end

#get_release_groupsObject



43
44
45
46
47
48
49
# File 'lib/musicbrainz/artist.rb', line 43

def get_release_groups
  release_groups=@metadata['artist']['release_group_list']['release_group']
  @release_groups=Array.new
  release_groups.each do |r|
    @release_groups<<OpenStruct.new(r)
  end
end

#get_releasesObject



35
36
37
38
39
40
41
# File 'lib/musicbrainz/artist.rb', line 35

def get_releases
  releases=@metadata['artist']['release_list']['release']
  @releases=Array.new
  releases.each do |r|
    @releases<<OpenStruct.new(r)
  end
end

#get_request(method, mbid, query = []) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/musicbrainz/artist.rb', line 22

def get_request(method, mbid, query=[])
  @request=self.class.get(method, mbid, query)
  @metadata=@request['metadata']
  get_releases if query.include?('releases')
  get_info if query.include?('info')
  get_release_groups if query.include?('release-groups')
  get_works if query.include?('works')
end

#get_worksObject



51
52
53
54
55
56
57
# File 'lib/musicbrainz/artist.rb', line 51

def get_works
  works=@metadata['artist']['work_list']['work']
  @works=Array.new
  works.each do |r|
    @works<<OpenStruct.new(r)
  end
end