Class: PlaylistCreator
- Inherits:
-
Object
- Object
- PlaylistCreator
- Defined in:
- lib/playlist_creator.rb
Instance Method Summary collapse
- #add(titlex = '', locationx = '', title: titlex, location: locationx, album: '') ⇒ Object
- #delete(id) ⇒ Object
- #find_by_title(title) ⇒ Object
-
#initialize(obj = nil) ⇒ PlaylistCreator
constructor
A new instance of PlaylistCreator.
- #to_dx ⇒ Object
- #to_xml ⇒ Object
- #to_xspf ⇒ Object
- #update(id, title: nil, location: nil, album: nil) ⇒ Object
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_dx ⇒ Object
68 69 70 |
# File 'lib/playlist_creator.rb', line 68 def to_dx() @dx.clone end |
#to_xml ⇒ Object
72 73 74 |
# File 'lib/playlist_creator.rb', line 72 def to_xml() @dx.to_xml pretty: true end |
#to_xspf ⇒ Object
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 |