Visibility shows wrong unit when SM are parsed
hvolkmer opened this issue · 2 comments
Repro:
Taking the example metar:
metar_string = "KHWD 280554Z AUTO 29007KT 10SM OVC008 14/12 A3002 RMK AO2 SLP176 T01390117 10211\n"
raw = Metar::Raw::Metar.new(metar_string)
parser = Metar::Parser.new(raw)
parser.visibility.distance
=> #<Metar::Data::Distance:0x007fdab0977df8 @units=:miles, @value=16093.44>
This is wrong/unexpected. It either needs to be
=> #<Metar::Data::Distance:0x007fdab0977df8 @units=:miles, @value=10000.00>
or
=> #<Metar::Data::Distance:0x007fdab0977df8 @units=:meters, @value=16093.44>
The bug seems to be in
https://github.com/joeyates/metar-parser/blob/master/lib/metar/data/visibility.rb#L20
https://github.com/joeyates/metar-parser/blob/master/lib/metar/data/visibility.rb#L27
https://github.com/joeyates/metar-parser/blob/master/lib/metar/data/visibility.rb#L33
When I try
Metar::Data::Distance.miles(10)
=> #<Metar::Data::Distance:0x007fdab08e6088 @units=:meters, @value=16093.44>
it is correct. It seems as if the units=:miles
is unnecessary. This is not caught by the specs.
Hello,
Sorry for the very late reply.
Due to the way that this gem handles values, based on the way the 'm9t' gem works, I think this is more a naming problem than a bug.
Internally, all values are held as SI units (with a slight variation for temperatures). So, distances will always be held as meters.
The instance variable @units
is there to store the desired units to use in .to_s
.
I'm going to change to name of the variable to .serialization_units
in order to avoid this confusion.
I've released version 1.4.0 with the update.