Class: Keenser::Song

Inherits:
Model
  • Object
show all
Defined in:
lib/keenser/model/song.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

each, #find_or_create, schema, without_tables

Instance Attribute Details

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#local_pathObject



21
22
23
# File 'lib/keenser/model/song.rb', line 21

def local_path
  "#{Computer.local.music}/#{path}"
end

#tag(name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/keenser/model/song.rb', line 25

def tag name
  # Make sure we're not creating a duplicate song record
  s = Song.where(path: path).first || (save; self)
  t = Tag.find_or_create name: name
  SongTag.find_or_create song_id: s.id, tag_id: t.id
  t.export!
end

#to_sObject



11
12
13
14
15
16
17
18
19
# File 'lib/keenser/model/song.rb', line 11

def to_s
  pre  = status == "playing" ? "" : "[#{status}] "
  disp = "#{pre}#{artist} - #{title}"
  if disp.length > 40
    disp.slice(0,39) + ""
  else
    disp.ljust 40
  end
end