Class: DvdprofilerInfo
- Inherits:
-
Object
- Object
- DvdprofilerInfo
- Defined in:
- lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb
Class Method Summary collapse
-
.find(options) ⇒ Object
Synopsis see DvdprofilerProfile.all for options really should include at least: :title, :year, :isbn, :filespec.
Instance Method Summary collapse
-
#box_set_parent_titles ⇒ Object
Synopsis try to find box set parent’s title.
-
#initialize(profile) ⇒ DvdprofilerInfo
constructor
A new instance of DvdprofilerInfo.
- #isbn ⇒ Object
- #production_years ⇒ Object
- #released_years ⇒ Object
-
#to_xbmc_info ⇒ Object
Synopsis map the given dvd_hash into a @movie hash.
-
#year ⇒ Object
Synopsis return the lowest production year as the year.
Constructor Details
#initialize(profile) ⇒ DvdprofilerInfo
Returns a new instance of DvdprofilerInfo.
3 4 5 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 3 def initialize(profile) @profile = profile end |
Class Method Details
.find(options) ⇒ Object
Synopsis
see DvdprofilerProfile.all for options really should include at least: :title, :year, :isbn, :filespec
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 10 def self.find() dvdprofiler_info = nil # find ISBN for each title and assign to the media profiles = DvdprofilerProfile.all() if profiles.length > 1 media_title = "#{[:title]}#{[:year].blank? ? '' : ' (' + [:year] + ')'}" Dvdprofiler2Xbmc.multiple_profiles << "#{media_title} #{profiles.collect{|prof| prof.isbn}.join(", ")}" AppConfig[:logger].warn { "Multiple profiles found for #{media_title}" } else profile = profiles.first unless profile.nil? AppConfig[:logger].info { "ISBN => #{[:isbn]}" } unless [:isbn].nil? profile.save([:filespec]) dvdprofiler_info = DvdprofilerInfo.new(profile) end end dvdprofiler_info end |
Instance Method Details
#box_set_parent_titles ⇒ Object
Synopsis
try to find box set parent’s title
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 81 def box_set_parent_titles titles = [] unless @profile.dvd_hash[:boxset].blank? begin AppConfig[:logger].debug { "Need to find box set parent's title" } parent_isbn = @profile.dvd_hash[:boxset].first['parent'].first unless parent_isbn.blank? parent_profile = DvdprofilerProfile.first(:isbn => parent_isbn) unless parent_profile.blank? titles << parent_profile.title titles += get_parent_titles(parent_profile.dvd_hash) end end rescue end end AppConfig[:logger].debug { "parent titles => #{titles.pretty_inspect}" } unless titles.empty? titles end |
#isbn ⇒ Object
69 70 71 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 69 def isbn @profile.isbn rescue nil end |
#production_years ⇒ Object
101 102 103 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 101 def production_years @profile.dvd_hash[:productionyear] rescue [] end |
#released_years ⇒ Object
105 106 107 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 105 def released_years @profile.dvd_hash[:released] rescue [] end |
#to_xbmc_info ⇒ Object
Synopsis
map the given dvd_hash into a @movie hash
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 55 def to_xbmc_info info = Hash.new unless @profile.dvd_hash.nil? @profile.dvd_hash[:genres] ||= [] info['genre'] = @profile.dvd_hash[:genres] unless @profile.dvd_hash[:genres].blank? info['title'] = @profile.dvd_hash[:title] info['year'] = [@profile.dvd_hash[:productionyear], @profile.dvd_hash[:released]].flatten.uniq.collect{|s| ((s =~ /(\d{4})/) ? $1 : nil)}.uniq.compact.first DVD_HASH_TO_INFO_MAP.each do |key, value| info[value] = @profile.dvd_hash[key] unless @profile.dvd_hash[key].blank? end end info end |
#year ⇒ Object
Synopsis
return the lowest production year as the year
75 76 77 |
# File 'lib/dvdprofiler2xbmc/models/dvdprofiler_info.rb', line 75 def year [@profile.dvd_hash[:productionyear]].flatten.uniq.compact.sort.first rescue nil end |