Class: Metar::Data::Lightning
Constant Summary collapse
- TYPE =
{'' => :default}.freeze
Instance Attribute Summary collapse
-
#directions ⇒ Object
Returns the value of attribute directions.
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw, frequency:, type:, distance:, directions:) ⇒ Lightning
constructor
A new instance of Lightning.
Methods inherited from Base
Constructor Details
#initialize(raw, frequency:, type:, distance:, directions:) ⇒ Lightning
Returns a new instance of Lightning.
74 75 76 77 78 79 80 |
# File 'lib/metar/data/lightning.rb', line 74 def initialize(raw, frequency:, type:, distance:, directions:) @raw = raw @frequency = frequency @type = type @distance = distance @directions = directions end |
Instance Attribute Details
#directions ⇒ Object
Returns the value of attribute directions.
72 73 74 |
# File 'lib/metar/data/lightning.rb', line 72 def directions @directions end |
#distance ⇒ Object
Returns the value of attribute distance.
71 72 73 |
# File 'lib/metar/data/lightning.rb', line 71 def distance @distance end |
#frequency ⇒ Object
Returns the value of attribute frequency.
69 70 71 |
# File 'lib/metar/data/lightning.rb', line 69 def frequency @frequency end |
#type ⇒ Object
Returns the value of attribute type.
70 71 72 |
# File 'lib/metar/data/lightning.rb', line 70 def type @type end |
Class Method Details
.compass?(direction) ⇒ Boolean
65 66 67 |
# File 'lib/metar/data/lightning.rb', line 65 def self.compass?(direction) direction =~ /^([NESW]|NE|SE|SW|NW)$/ end |
.parse_chunks(chunks) ⇒ Object
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metar/data/lightning.rb', line 8 def self.parse_chunks(chunks) raw = chunks.shift m = raw.match(/^LTG(|CG|IC|CC|CA)$/) raise 'first chunk is not lightning' if m.nil? type = TYPE[m[1]] frequency = nil distance = nil directions = [] if chunks[0] == 'DSNT' distance = Metar::Data::Distance.miles(10) # Should be >10SM, not 10SM raw += " " + chunks.shift end loop do break if chunks[0].nil? if compass?(chunks[0]) direction = chunks.shift raw += " " + direction directions << direction next end if chunks[0] == 'ALQDS' directions += %w(N E S W) raw += " " + chunks.shift next end m = chunks[0].match(/^([NESW]{1,2})-([NESW]{1,2})$/) if m break if !compass?(m[1]) break if !compass?(m[2]) directions += [m[1], m[2]] raw += " " + chunks.shift next end if chunks[0] == 'AND' raw += " " + chunks.shift next end break end new( raw, frequency: frequency, type: type, distance: distance, directions: directions ) end |