Class: LyricsSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/lyrics_search.rb,
lib/lyrics_search/version.rb

Defined Under Namespace

Classes: SearchResults

Constant Summary collapse

CHARTLYRICS_CLIENT =
Savon.client(wsdl: 'http://api.chartlyrics.com/apiv1.asmx?WSDL')
VERSION =
"0.1.0"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LyricsSearch

Returns a new instance of LyricsSearch.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lyrics_search.rb', line 15

def initialize(options = {})
  @artist, @song, @lyrics = options.values_at(:artist, :song, :lyrics)
  
  begin
    search_type = "search_lyric#{'_text' if @lyrics}"
    @search_results = SearchResults.new(CHARTLYRICS_CLIENT.call(
                                        search_type.to_sym, message: {artist: @artist, song: @song, lyric_text: @lyrics}).body,
                                        search_type)

    if search_results.results
      instance_eval do
        def get_result; search_results.results.first.get_result; end
        def get_all_results; search_results.results.map(&:get_result); end
        def get_lyrics; search_results.results.first.lyrics; end
        def get_all_lyrics; search_results.results.map(&:lyrics); end
        def get_raw_results; search_results.results.map(&:raw_result); end
      end
    end
  rescue
    self.class.invalid_message
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



38
39
40
# File 'lib/lyrics_search.rb', line 38

def method_missing(m, *args, &block)
  self.class.invalid_message
end

Class Attribute Details

.invalid_messageObject

Returns the value of attribute invalid_message.



12
13
14
# File 'lib/lyrics_search.rb', line 12

def invalid_message
  @invalid_message
end

Instance Attribute Details

#search_resultsObject (readonly)

Returns the value of attribute search_results.



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

def search_results
  @search_results
end