Class: RailsMaint::Schedule
- Inherits:
-
Object
- Object
- RailsMaint::Schedule
- Defined in:
- lib/rails_maint/schedule.rb
Instance Attribute Summary collapse
-
#enabled_at ⇒ Object
readonly
Returns the value of attribute enabled_at.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Class Method Summary collapse
Instance Method Summary collapse
- #active?(now = Time.now) ⇒ Boolean
-
#initialize(enabled_at: nil, start_time: nil, end_time: nil) ⇒ Schedule
constructor
A new instance of Schedule.
- #seconds_until_end(now = Time.now) ⇒ Object
Constructor Details
#initialize(enabled_at: nil, start_time: nil, end_time: nil) ⇒ Schedule
Returns a new instance of Schedule.
10 11 12 13 14 |
# File 'lib/rails_maint/schedule.rb', line 10 def initialize(enabled_at: nil, start_time: nil, end_time: nil) @enabled_at = enabled_at @start_time = start_time @end_time = end_time end |
Instance Attribute Details
#enabled_at ⇒ Object (readonly)
Returns the value of attribute enabled_at.
8 9 10 |
# File 'lib/rails_maint/schedule.rb', line 8 def enabled_at @enabled_at end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
8 9 10 |
# File 'lib/rails_maint/schedule.rb', line 8 def end_time @end_time end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/rails_maint/schedule.rb', line 8 def start_time @start_time end |
Class Method Details
.load(path) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/rails_maint/schedule.rb', line 16 def self.load(path) return new unless File.exist?(path) content = File.read(path).strip return new unless content.length.positive? parse(content) end |
Instance Method Details
#active?(now = Time.now) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rails_maint/schedule.rb', line 25 def active?(now = Time.now) return false if @enabled_at.nil? && @start_time.nil? if @start_time return false if now < @start_time return false if @end_time && now > @end_time end true end |
#seconds_until_end(now = Time.now) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rails_maint/schedule.rb', line 36 def seconds_until_end(now = Time.now) return nil unless @end_time remaining = (@end_time - now).ceil remaining.positive? ? remaining : nil end |