class GetActiveStations
Constants
- FILE_PATH
Public Class Methods
water_level()
click to toggle source
# File lib/get_active_stations.rb, line 11 def self.water_level self.pull_data if @@water_level.size == 0 @@water_level end
winds()
click to toggle source
# File lib/get_active_stations.rb, line 16 def self.winds self.pull_data if @@winds.size == 0 @@winds end
Private Class Methods
doc()
click to toggle source
# File lib/get_active_stations.rb, line 22 def self.doc @@doc end
pull_data()
click to toggle source
# File lib/get_active_stations.rb, line 27 def self.pull_data @@doc = [] @@water_level = [] @@winds = [] @@doc = File.open(FILE_PATH) { |f| Nokogiri::XML(f) } stations = self.doc.xpath("//stationV2") stations.each_entry do |e| iD = e.xpath(".").attribute("ID").value name = e.xpath(".").attribute("name").value handle = e.xpath("./metadataV2/shef_id")[0].text state = e.xpath("./metadataV2/location/state")[0].text lat = e.xpath("./metadataV2/location/lat")[0].text local = ((state == "NY") || (state == "NJ") || (state == "CT")) water = e.xpath("./parameter[contains(@name, 'Water Level')]") winds = e.xpath("./parameter[contains(@name, 'Winds')]") sta = Station.new sta.iD = iD sta.name = name sta.handle = handle sta.state = state sta.water_level = water.size > 0 sta.winds = winds.size > 0 @@winds << sta if local && sta.winds @@water_level << sta if local && sta.water_level && lat.to_f < 42.5 # the latitude restriction pevents weird lake depth calculation data from getting into the data. end end