Class: Metar::Raw::Metar

Inherits:
Base
  • Object
show all
Defined in:
lib/metar/raw.rb

Overview

Use this class when you only have a METAR string. The date of the reading is decided as follows:

  • the day of the month is extracted from the METAR,

  • the most recent day with that day of the month is taken as the date of the reading.

Instance Attribute Summary

Attributes inherited from Base

#metar

Instance Method Summary collapse

Constructor Details

#initialize(metar) ⇒ Metar

Returns a new instance of Metar.



39
40
41
42
# File 'lib/metar/raw.rb', line 39

def initialize(metar)
  @metar = metar
  @time = nil
end

Instance Method Details

#timeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/metar/raw.rb', line 44

def time
  return @time if @time

  dom = day_of_month
  date = Date.today
  loop do
    if date.day >= dom
      @time = Date.new(date.year, date.month, dom)
      break
    end
    # skip to the last day of the previous month
    date = Date.new(date.year, date.month, 1).prev_day
  end
  @time
end