Class: MusicBrainz::Query
Instance Attribute Summary collapse
-
#fetch ⇒ Object
Returns the value of attribute fetch.
-
#original_query ⇒ Object
Returns the value of attribute original_query.
-
#results ⇒ Object
Returns the value of attribute results.
-
#score ⇒ Object
Returns the value of attribute score.
-
#top_match ⇒ Object
Returns the value of attribute top_match.
Instance Method Summary collapse
- #get_query(method, query, fetch = []) ⇒ Object
-
#initialize(query, method, fetch) ⇒ Query
constructor
A new instance of Query.
- #inspect ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(query, method, fetch) ⇒ Query
Returns a new instance of Query.
9 10 11 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/query.rb', line 9 def initialize(query, method, fetch) method=method[:entity] fetch=fetch[:fetch] @fetch=fetch if fetch.is_a?(Hash) && fetch.present? && fetch.has_key?(:fetch) @fetch=fetch if fetch.is_a?(Array) && fetch.present? @fetch=Array.new<<fetch if fetch.is_a?(String) && fetch.present? available_methods=['artist', 'release', 'release-group', 'recording', 'work', 'label'] method= available_methods.include?(method) ? method : nil if query.kind_of?(String) @query= query.is_mbid ? [:mbid, query] : query elsif query.kind_of?(Hash) @query=Hash.new query.each_pair do |k, v| @query[k]=v end else return false end #Now, transferring to query format. query_a=Array.new @query.each_pair do |k, v| if k==:date v=v.to_date v="#{v-7.days} TO #{v}" end query_a<<"#{k}:#{v}" end @original_query=query_a query_s=String.new query_s=URI.encode(query_a.join("AND")) #Dealing with non-mbid... get_query(method, query_s,fetch) end |
Instance Attribute Details
#fetch ⇒ Object
Returns the value of attribute fetch.
7 8 9 |
# File 'lib/musicbrainz/query.rb', line 7 def fetch @fetch end |
#original_query ⇒ Object
Returns the value of attribute original_query.
4 5 6 |
# File 'lib/musicbrainz/query.rb', line 4 def original_query @original_query end |
#results ⇒ Object
Returns the value of attribute results.
3 4 5 |
# File 'lib/musicbrainz/query.rb', line 3 def results @results end |
#score ⇒ Object
Returns the value of attribute score.
5 6 7 |
# File 'lib/musicbrainz/query.rb', line 5 def score @score end |
#top_match ⇒ Object
Returns the value of attribute top_match.
6 7 8 |
# File 'lib/musicbrainz/query.rb', line 6 def top_match @top_match end |
Instance Method Details
#get_query(method, query, fetch = []) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/musicbrainz/query.rb', line 47 def get_query(method, query,fetch=[]) puts method puts query puts fetch @request=self.class.get_query_path(method, query) #Find the highest score. @results=@request list="#{method}_list" case method when 'release' @results=@request['metadata'][list][method] @score=@results[0]['ext:score'] if @score=='100' puts @results[0]['id'] @top_match=MusicBrainz::Release.new(@results[0]['id'], fetch) end when 'artist' @results=@request['metadata'][list][method] @score=@results[0]['ext:score'] if @score=='100' @top_match=MusicBrainz::Artist.new(@results['id'], fetch) end when 'release-group' when 'recording' when 'work' when 'label' end end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/musicbrainz/query.rb', line 43 def inspect "#{@method} ,#{@query} : #{@results}, #{@score}" end |