Class: XbmcInfo
- Inherits:
-
Object
- Object
- XbmcInfo
- Defined in:
- lib/dvdprofiler2xbmc/models/xbmc_info.rb
Overview
Synopsis
This is the model for the XBMC’s Info profile which is used to manage a .nfo file
Usage:
profile = XbmcInfo.new(media.path_to(:nfo))
profile.movie = ‘some value’ puts profile.movie puts profile.to_xml puts profile.save
Instance Method Summary collapse
-
#initialize(filespec) ⇒ XbmcInfo
constructor
Synopsis filespec => String pathspec to the .nfo file.
-
#movie ⇒ Object
Synopsis return the movie hash that contains the media meta data.
-
#movie=(other) ⇒ Object
Synopsis set the movie hash.
-
#save ⇒ Object
Synopsis save the profile to the .nfo file, but only if it has changed.
-
#to_xml ⇒ Object
Synopsis convert the @movie hash into xml and return the xml as a String.
Constructor Details
#initialize(filespec) ⇒ XbmcInfo
Synopsis
filespec => String pathspec to the .nfo file
18 19 20 21 22 23 |
# File 'lib/dvdprofiler2xbmc/models/xbmc_info.rb', line 18 def initialize(filespec) @nfo_filespec = filespec @movie = nil @original_movie = nil load end |
Instance Method Details
#movie ⇒ Object
Synopsis
return the movie hash that contains the media meta data
27 28 29 30 |
# File 'lib/dvdprofiler2xbmc/models/xbmc_info.rb', line 27 def movie @movie ||= Hash.new @movie end |
#movie=(other) ⇒ Object
Synopsis
set the movie hash
34 35 36 |
# File 'lib/dvdprofiler2xbmc/models/xbmc_info.rb', line 34 def movie=(other) @movie = other end |
#save ⇒ Object
Synopsis
save the profile to the .nfo file, but only if it has changed
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dvdprofiler2xbmc/models/xbmc_info.rb', line 56 def save begin if dirty? xml = self.to_xml unless xml.blank? AppConfig[:logger].info { "updated #{@nfo_filespec}"} DvdProfiler2Xbmc.save_to_file(@nfo_filespec, xml) end end rescue Exception => e AppConfig[:logger].error "Unable to save xbmc info to #{@nfo_filespec} - #{e.to_s}" end end |
#to_xml ⇒ Object
Synopsis
convert the @movie hash into xml and return the xml as a String
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dvdprofiler2xbmc/models/xbmc_info.rb', line 40 def to_xml xml = '' begin unless @movie.blank? data = filter(@movie.dup) xml = XmlSimple.xml_out(data, 'NoAttr' => true, 'RootName' => 'movie') end rescue Exception => e AppConfig[:logger].error { "Error creating nfo file - " + e.to_s} raise e end xml end |