Class: PlaylistCreator

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

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil) ⇒ PlaylistCreator

Returns a new instance of PlaylistCreator.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/playlist_creator.rb', line 41

def initialize(obj=nil)

  @dx = if obj.is_a? String then
    header = "<?dynarex schema='tracklist/track(location, title, " +
        "album)'?>\n--+\n"
    Dynarex.new(header + obj)
  elsif  obj.is_a? Dynarex
    obj
  else
    Dynarex.new('tracklist/track(location, title, album)')
  end

end

Instance Method Details

#add(titlex = '', locationx = '', title: titlex, location: locationx, album: '') ⇒ Object



55
56
57
58
# File 'lib/playlist_creator.rb', line 55

def add(titlex='', locationx='', title: titlex,
        location: locationx, album: '')
  @dx.create({title: title, location: location, album: album})
end

#delete(id) ⇒ Object



60
61
62
# File 'lib/playlist_creator.rb', line 60

def delete(id)
  @dx.delete id
end

#find_by_title(title) ⇒ Object



64
65
66
# File 'lib/playlist_creator.rb', line 64

def find_by_title(title)
  @dx.all.select {|x| x.title[/#{title}/i]}
end

#to_dxObject



68
69
70
# File 'lib/playlist_creator.rb', line 68

def to_dx()
  @dx.clone
end

#to_xmlObject



72
73
74
# File 'lib/playlist_creator.rb', line 72

def to_xml()
  @dx.to_xml pretty: true
end

#to_xspfObject



76
77
78
79
80
# File 'lib/playlist_creator.rb', line 76

def to_xspf()
  doc   = Nokogiri::XML(@dx.to_xml(pretty: true))
  xslt  = Nokogiri::XSLT(XSLT_DX)
  xslt.transform(doc).to_xml
end

#update(id, title: nil, location: nil, album: nil) ⇒ Object



82
83
84
# File 'lib/playlist_creator.rb', line 82

def update(id, title: nil, location: nil, album: nil)
  @dx.update(id, {title: title, location: location, album: album})
end