Class: WeatherGov::ValidTime
- Inherits:
-
Object
- Object
- WeatherGov::ValidTime
- Defined in:
- lib/weather_gov/valid_time.rb
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ Object
- #elapsed(time = Time.now) ⇒ Object
- #end_time ⇒ Object
- #fields ⇒ Object
-
#initialize(valid_time_string) ⇒ ValidTime
constructor
A new instance of ValidTime.
- #range ⇒ Object
- #remaining(time = Time.now) ⇒ Object
- #start_time ⇒ Object
- #valid?(time = Time.now) ⇒ Boolean
Constructor Details
#initialize(valid_time_string) ⇒ ValidTime
Returns a new instance of ValidTime.
12 13 14 |
# File 'lib/weather_gov/valid_time.rb', line 12 def initialize(valid_time_string) @valid_time_string = valid_time_string end |
Class Method Details
Instance Method Details
#duration ⇒ Object
24 25 26 |
# File 'lib/weather_gov/valid_time.rb', line 24 def duration @duration ||= ActiveSupport::Duration.parse(fields.last) end |
#elapsed(time = Time.now) ⇒ Object
40 41 42 |
# File 'lib/weather_gov/valid_time.rb', line 40 def elapsed(time = Time.now) ActiveSupport::Duration.build(time - start_time) end |
#end_time ⇒ Object
28 29 30 |
# File 'lib/weather_gov/valid_time.rb', line 28 def end_time start_time + duration end |
#fields ⇒ Object
16 17 18 |
# File 'lib/weather_gov/valid_time.rb', line 16 def fields @fields ||= @valid_time_string.split("/") end |
#range ⇒ Object
32 33 34 |
# File 'lib/weather_gov/valid_time.rb', line 32 def range start_time...end_time end |
#remaining(time = Time.now) ⇒ Object
44 45 46 |
# File 'lib/weather_gov/valid_time.rb', line 44 def remaining(time = Time.now) ActiveSupport::Duration.build(end_time - time) end |
#start_time ⇒ Object
20 21 22 |
# File 'lib/weather_gov/valid_time.rb', line 20 def start_time @start_time ||= Time.parse(fields.first) end |
#valid?(time = Time.now) ⇒ Boolean
36 37 38 |
# File 'lib/weather_gov/valid_time.rb', line 36 def valid?(time = Time.now) range.include?(time) end |