Class: MediaWikiLyrics::AlbumData

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracks, title, year, month = 0, day = 0, various_artists_name = "(Various Artists)") ⇒ AlbumData

NOTE: the artist is obtained from the tracks data. If it’s not the same for all tracks it would be varios_artists_name.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/lyrics/mediawikilyrics.rb', line 57

def initialize( tracks, title, year, month=0, day=0, various_artists_name="(Various Artists)" )

	raise "tracks, title and year values can't be nil" if ! title || ! year || ! tracks
	raise "tracks value can't be empty" if tracks.empty?

	@tracks = tracks.clone().freeze()
	@title = title.strip().freeze()
	@year = year.kind_of?( String ) ? year.strip().to_i() : year.to_i()
	@month = month.kind_of?( String ) ? month.strip().to_i() : month.to_i()
	@day = day.kind_of?( String ) ? day.strip().to_i() : day.to_i()
	@various_artists_name = various_artists_name.strip().freeze()

	@artist = nil
	@genres = []
	genre = nil
	normalized_artist = nil
	@length = 0
	@tracks.each() do |track|
		if @artist == nil
			@artist = track.artist
			normalized_artist = Strings.normalize( @artist )
		elsif normalized_artist != Strings.normalize( track.artist )
			@artist = various_artists_name
		end
		if track.genre && ! @genres.include?( genre = String.capitalize( track.genre, true ) )
			@genres.insert( -1, genre )
		end
		@length += track.length
	end
	@genres.freeze()

end

Instance Attribute Details

#artistObject (readonly)

Returns the value of attribute artist.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def artist
  @artist
end

#dayObject (readonly)

Returns the value of attribute day.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def day
  @day
end

#genresObject (readonly)

Returns the value of attribute genres.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def genres
  @genres
end

#lengthObject (readonly)

Returns the value of attribute length.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def length
  @length
end

#monthObject (readonly)

Returns the value of attribute month.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def month
  @month
end

#titleObject (readonly)

Returns the value of attribute title.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def title
  @title
end

#tracksObject (readonly)

Returns the value of attribute tracks.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def tracks
  @tracks
end

#yearObject (readonly)

Returns the value of attribute year.



53
54
55
# File 'lib/lyrics/mediawikilyrics.rb', line 53

def year
  @year
end

Instance Method Details

#various_artists?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/lyrics/mediawikilyrics.rb', line 90

def various_artists?()
	return @artist == @various_artists_name
end