Class: Metar::Data::Time
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#hour ⇒ Object
readonly
Returns the value of attribute hour.
-
#minute ⇒ Object
readonly
Returns the value of attribute minute.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#strict ⇒ Object
readonly
Returns the value of attribute strict.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw, strict:, year:, month:, day:, hour:, minute:) ⇒ Time
constructor
A new instance of Time.
- #value ⇒ Object
Constructor Details
#initialize(raw, strict:, year:, month:, day:, hour:, minute:) ⇒ Time
Returns a new instance of Time.
48 49 50 51 52 53 54 55 56 |
# File 'lib/metar/data/time.rb', line 48 def initialize(raw, strict:, year:, month:, day:, hour:, minute:) @raw = raw @strict = strict @year = year @month = month @day = day @hour = hour @minute = minute end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
44 45 46 |
# File 'lib/metar/data/time.rb', line 44 def day @day end |
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
45 46 47 |
# File 'lib/metar/data/time.rb', line 45 def hour @hour end |
#minute ⇒ Object (readonly)
Returns the value of attribute minute.
46 47 48 |
# File 'lib/metar/data/time.rb', line 46 def minute @minute end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
43 44 45 |
# File 'lib/metar/data/time.rb', line 43 def month @month end |
#strict ⇒ Object (readonly)
Returns the value of attribute strict.
41 42 43 |
# File 'lib/metar/data/time.rb', line 41 def strict @strict end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
42 43 44 |
# File 'lib/metar/data/time.rb', line 42 def year @year end |
Class Method Details
.parse(raw, year: nil, month: nil, strict: true) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/metar/data/time.rb', line 6 def self.parse(raw, year: nil, month: nil, strict: true) year ||= DateTime.now.year month ||= DateTime.now.month date_matcher = if strict /^(\d{2})(\d{2})(\d{2})Z$/ else /^(\d{1,2})(\d{2})(\d{2})Z$/ end m1 = raw.match(date_matcher) if m1 day = m1[1].to_i hour = m1[2].to_i minute = m1[3].to_i else return nil if strict m2 = raw.match(/^(\d{1,2})(\d{2})Z$/) return nil if !m2 # The day is missing, use today's date day = ::Time.now.day hour = m2[1].to_i minute = m2[2].to_i end new( raw, strict: strict, year: year, month: month, day: day, hour: hour, minute: minute ) end |
Instance Method Details
#value ⇒ Object
58 59 60 |
# File 'lib/metar/data/time.rb', line 58 def value ::Time.gm(year, month, day, hour, minute) end |