Class: Lyrics::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/wiki_lyrics/lyrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Response

Returns a new instance of Response.



61
62
63
64
65
66
67
68
69
70
# File 'lib/wiki_lyrics/lyrics.rb', line 61

def initialize( request )
	raise "request can't be nil" if ! request
	@request = request
	@artist = nil
	@title = nil
	@album = nil
	@year = nil
	@lyrics = nil
	@custom_data = {}
end

Instance Attribute Details

#albumObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def album
  @album
end

#artistObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def artist
  @artist
end

#custom_dataObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def custom_data
  @custom_data
end

#lyricsObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def lyrics
  @lyrics
end

#requestObject (readonly)

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def request
  @request
end

#titleObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def title
  @title
end

#urlObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def url
  @url
end

#yearObject

, :suggestions



58
59
60
# File 'lib/wiki_lyrics/lyrics.rb', line 58

def year
  @year
end

Instance Method Details

#album_modified?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/wiki_lyrics/lyrics.rb', line 112

def album_modified?()
	return @album && @album != request.album
end

#artist_modified?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/wiki_lyrics/lyrics.rb', line 96

def artist_modified?()
	return @artist && @artist != request.artist
end

#each_modifiedObject



92
93
94
# File 'lib/wiki_lyrics/lyrics.rb', line 92

def each_modified()
	each_modified!() { |k, v| yield k, v.clone() }
end

#each_modified! {|"artist", @artist| ... } ⇒ Object

Yields:



85
86
87
88
89
90
# File 'lib/wiki_lyrics/lyrics.rb', line 85

def each_modified!()
	yield "artist", @artist if artist_modified?()
	yield "title", @title if title_modified?()
	yield "album", @album if album_modified?()
	yield "year", @year if year_modified?()
end

#title_modified?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/wiki_lyrics/lyrics.rb', line 104

def title_modified?()
	return @title && @title != request.title
end

#to_sObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/wiki_lyrics/lyrics.rb', line 72

def to_s()
	ret = ""
	ret << "\n - response artist: #{@artist}" if @artist
	ret << "\n - response title: #{@title}" if @title
	ret << "\n - response album: #{@album}" if @album
	ret << "\n - response year: #{@year}" if @year
	if @custom_data.size > 0
		ret << "\n - response custom data:"
		@custom_data.each { |key, val| ret << "\n    - #{key}: #{val}" }
	end
	return ret.size > 0 ? ret.slice( 1..-1 ) : ret
end

#year_modified?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/wiki_lyrics/lyrics.rb', line 120

def year_modified?()
	return @year && @year != request.year
end