Class: WeatherGov::ValidTime

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_gov/valid_time.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.parse(valid_time_string) ⇒ Object



8
9
10
# File 'lib/weather_gov/valid_time.rb', line 8

def self.parse(valid_time_string)
  ValidTime.new(valid_time_string)
end

Instance Method Details

#durationObject



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_timeObject



28
29
30
# File 'lib/weather_gov/valid_time.rb', line 28

def end_time
  start_time + duration
end

#fieldsObject



16
17
18
# File 'lib/weather_gov/valid_time.rb', line 16

def fields
  @fields ||= @valid_time_string.split("/")
end

#rangeObject



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_timeObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/weather_gov/valid_time.rb', line 36

def valid?(time = Time.now)
  range.include?(time)
end