Class: Metar::Station
- Inherits:
-
Object
- Object
- Metar::Station
- Defined in:
- lib/metar/station.rb
Constant Summary collapse
- NOAA_STATION_LIST_URL =
'https://tgftp.nws.noaa.gov/data/nsd_cccc.txt'
Instance Attribute Summary collapse
-
#cccc ⇒ Object
(also: #code)
readonly
Returns the value of attribute cccc.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
- .all ⇒ Object
- .all_structures ⇒ Object
- .countries ⇒ Object
- .download_stations ⇒ Object
-
.exist?(cccc) ⇒ Boolean
Does the given CCCC code exist?.
- .find_all_by_country(country) ⇒ Object
- .find_by_cccc(cccc) ⇒ Object
- .find_data_by_cccc(cccc) ⇒ Object
- .to_latitude(latitude) ⇒ Object
- .to_longitude(longitude) ⇒ Object
Instance Method Summary collapse
-
#initialize(cccc, noaa_data) ⇒ Station
constructor
No check is made on the existence of the station.
- #parser ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(cccc, noaa_data) ⇒ Station
No check is made on the existence of the station
64 65 66 67 68 69 70 |
# File 'lib/metar/station.rb', line 64 def initialize(cccc, noaa_data) raise "Station identifier must not be nil" if cccc.nil? raise "Station identifier must not be empty" if cccc.to_s == '' @cccc = cccc load! noaa_data end |
Instance Attribute Details
#cccc ⇒ Object (readonly) Also known as: code
Returns the value of attribute cccc.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def cccc @cccc end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def country @country end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def longitude @longitude end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def name @name end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def raw @raw end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
60 61 62 |
# File 'lib/metar/station.rb', line 60 def state @state end |
Class Method Details
.all ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/metar/station.rb', line 24 def all all_structures.collect do |h| = h.clone cccc = .delete(:cccc) new(cccc, ) end end |
.all_structures ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/metar/station.rb', line 92 def all_structures return @structures if @structures @nsd_cccc ||= download_stations @structures = [] @nsd_cccc.each_line do |station| fields = station.split(';') @structures << { cccc: fields[0], name: fields[3], state: fields[4], country: fields[5], latitude: fields[7], longitude: fields[8], raw: station.clone } end @structures end |
.countries ⇒ Object
20 21 22 |
# File 'lib/metar/station.rb', line 20 def countries all_structures.reduce(Set.new) { |a, s| a.add(s[:country]) }.to_a.sort end |
.download_stations ⇒ Object
86 87 88 89 90 |
# File 'lib/metar/station.rb', line 86 def download_stations uri = URI.parse(NOAA_STATION_LIST_URL) response = Net::HTTP.get_response(uri) response.body end |
.exist?(cccc) ⇒ Boolean
Does the given CCCC code exist?
37 38 39 |
# File 'lib/metar/station.rb', line 37 def exist?(cccc) !find_data_by_cccc(cccc).nil? end |
.find_all_by_country(country) ⇒ Object
41 42 43 |
# File 'lib/metar/station.rb', line 41 def find_all_by_country(country) all.select { |s| s.country == country } end |
.find_by_cccc(cccc) ⇒ Object
32 33 34 |
# File 'lib/metar/station.rb', line 32 def find_by_cccc(cccc) all.find { |station| station.cccc == cccc } end |
.find_data_by_cccc(cccc) ⇒ Object
114 115 116 |
# File 'lib/metar/station.rb', line 114 def find_data_by_cccc(cccc) all_structures.find { |station| station[:cccc] == cccc } end |
.to_latitude(latitude) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/metar/station.rb', line 52 def to_latitude(latitude) m = latitude.match(/^(\d+)-(\d+)([SN])/) return nil if !m (m[3] == 'N' ? 1.0 : -1.0) * (m[1].to_f + m[2].to_f / 60.0) end |
.to_longitude(longitude) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/metar/station.rb', line 45 def to_longitude(longitude) m = longitude.match(/^(\d+)-(\d+)([EW])/) return nil if !m (m[3] == 'E' ? 1.0 : -1.0) * (m[1].to_f + m[2].to_f / 60.0) end |