Class: MikePlayer::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/mikeplayer/song.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Song

Returns a new instance of Song.



5
6
7
8
# File 'lib/mikeplayer/song.rb', line 5

def initialize(filename)
  @filename = filename
  @mp3info  = Mp3Info.new(filename)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/mikeplayer/song.rb', line 3

def filename
  @filename
end

Class Method Details

.as_duration_str(l, t = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mikeplayer/song.rb', line 37

def self.as_duration_str(l, t = nil)
  l_hr  = "%02d" % (l / 3600).floor
  l_min = "%02d" % ((l % 3600 )/ 60).floor
  l_sec = "%02d" % (l % 60)
  e_min = "%02d" % (t / 60).floor unless t.nil?
  e_sec = "%02d" % (t % 60) unless t.nil?

  result = "#{l_min}:#{l_sec}"
  result = "#{l_hr}:#{result}" if l >= 3600
  result = "#{e_min}:#{e_sec} [#{result}]" unless t.nil?

  return result
end

Instance Method Details

#infoObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mikeplayer/song.rb', line 10

def info
  artist = "#{@mp3info.tag.artist}"
  title  = "#{@mp3info.tag.title}"

  if (true == artist.empty?) && (true == title.empty?)
    return File.basename(@filename, '.mp3')
  elsif (true == artist.empty?)
    artist = "?????"
  elsif (true == title.empty?)
    title  = "?????"
  end

  return "#{artist} - #{title}"
end

#lengthObject



25
26
27
# File 'lib/mikeplayer/song.rb', line 25

def length
  return @mp3info.length || 0
end

#length_str(elapsed_time) ⇒ Object



29
30
31
# File 'lib/mikeplayer/song.rb', line 29

def length_str(elapsed_time)
  return Song.as_duration_str(self.length, elapsed_time)
end

#to_jsonObject



33
34
35
# File 'lib/mikeplayer/song.rb', line 33

def to_json
  return @filename.to_s
end