Class: SimplePvr::Model::Programme
- Inherits:
-
Object
- Object
- SimplePvr::Model::Programme
- Includes:
- DataMapper::Resource
- Defined in:
- lib/simple_pvr/model/programme.rb
Class Method Summary collapse
- .add(channel, title, subtitle, description, start_time, duration, episode_num, icon_url = nil) ⇒ Object
- .clear ⇒ Object
- .on_channel_with_title(channel, title) ⇒ Object
- .on_channel_with_title_and_start_time(channel, title, start_time) ⇒ Object
- .titles_containing(text) ⇒ Object
- .with_title(title) ⇒ Object
- .with_title_containing(text) ⇒ Object
Instance Method Summary collapse
Class Method Details
.add(channel, title, subtitle, description, start_time, duration, episode_num, icon_url = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simple_pvr/model/programme.rb', line 38 def self.add(channel, title, subtitle, description, start_time, duration, episode_num, icon_url=nil) channel.programmes.create( channel: channel, title: title, subtitle: subtitle, description: description, start_time: start_time, duration: duration.to_i, episode_num: episode_num, icon_url: icon_url) end |
.clear ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/simple_pvr/model/programme.rb', line 30 def self.clear ProgrammeCategory.destroy ProgrammeDirector.destroy ProgrammePresenter.destroy ProgrammeActor.destroy Programme.destroy end |
.on_channel_with_title(channel, title) ⇒ Object
54 55 56 |
# File 'lib/simple_pvr/model/programme.rb', line 54 def self.on_channel_with_title(channel, title) Programme.all(channel: channel, title: title, order: :start_time) end |
.on_channel_with_title_and_start_time(channel, title, start_time) ⇒ Object
58 59 60 |
# File 'lib/simple_pvr/model/programme.rb', line 58 def self.on_channel_with_title_and_start_time(channel, title, start_time) Programme.all(channel: channel, title: title, start_time: start_time) end |
.titles_containing(text) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/simple_pvr/model/programme.rb', line 62 def self.titles_containing(text) # Maybe there's a smarter way to do substring search than constructing "%#{text}%"? I'd like # a version where the original input is escaped properly. However, this method is not # dangerous, it just means that the user can enter "%" or "_" in the search string for a # wildcard. Programme.all(:title.like => "%#{text}%", fields: [:title], order: :title, limit: 8, unique: true).map {|programme| programme.title } end |
.with_title(title) ⇒ Object
50 51 52 |
# File 'lib/simple_pvr/model/programme.rb', line 50 def self.with_title(title) Programme.all(title: title, order: :start_time) end |
.with_title_containing(text) ⇒ Object
70 71 72 73 |
# File 'lib/simple_pvr/model/programme.rb', line 70 def self.with_title_containing(text) # Same "LIKE" comments as above... Programme.all(:title.like => "%#{text}%", order: :start_time, limit: 20) end |
Instance Method Details
#end_time ⇒ Object
22 23 24 |
# File 'lib/simple_pvr/model/programme.rb', line 22 def end_time @start_time.advance(seconds: duration) end |
#outdated? ⇒ Boolean
26 27 28 |
# File 'lib/simple_pvr/model/programme.rb', line 26 def outdated? end_time < Time.now end |