Class: NDBC::Station

Inherits:
Object
  • Object
show all
Includes:
StationTable
Defined in:
lib/ndbc/station.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StationTable

station_table_data

Constructor Details

#initialize(id, station_data = {}) ⇒ Station

Returns a new instance of Station.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ndbc/station.rb', line 20

def initialize(id, station_data = {})
  @id = id.to_s
  @owner = station_data[:owner]
  @ttype = station_data[:ttype]
  @hull = station_data[:hull]
  @name = station_data[:name]
  @payload = station_data[:payload]
  @location = station_data[:location]
  @timezone = station_data[:timezone]
  @forecast = station_data[:forecast]
  @note = station_data[:note]
  @active = station_data[:active]
  @tide_station_id = station_data[:tide_station_id]
  @connection = Connection.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ndbc/station.rb', line 80

def method_missing(method_sym, *arguments, &block)
  upcased_method_name = method_sym.to_s.upcase
  case method_sym
  when :wdir, :wspd, :gst, :wvht, :dpd, :apd, :mwd,
       :pres, :atmp, :wtmp, :dewp, :vis, :ptdy, :tide
    latest_standard_meteorological_data[upcased_method_name]
  when :dir, :spd, :gdr, :gsp, :gtime
    latest_continuous_winds_data[upcased_method_name]
  when :h0, :wwh, :wwp, :wwd, :steepness, :avp
    latest_spectral_wave_summaries[upcased_method_name]
  when :swh
    latest_spectral_wave_summaries['SwH']
  when :swp
    latest_spectral_wave_summaries['SwP']
  when :swd
    latest_spectral_wave_summaries['SwD']
  else
    super
  end
end

Instance Attribute Details

#activeObject (readonly) Also known as: active?

Returns the value of attribute active.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def active
  @active
end

#connectionObject

Returns the value of attribute connection.



14
15
16
# File 'lib/ndbc/station.rb', line 14

def connection
  @connection
end

#forecastObject (readonly)

Returns the value of attribute forecast.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def forecast
  @forecast
end

#hullObject (readonly)

Returns the value of attribute hull.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def hull
  @hull
end

#idObject

Returns the value of attribute id.



14
15
16
# File 'lib/ndbc/station.rb', line 14

def id
  @id
end

#locationObject (readonly)

Returns the value of attribute location.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def name
  @name
end

#noteObject (readonly)

Returns the value of attribute note.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def note
  @note
end

#ownerObject (readonly)

Returns the value of attribute owner.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def owner
  @owner
end

#payloadObject (readonly)

Returns the value of attribute payload.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def payload
  @payload
end

#tide_station_idObject (readonly)

Returns the value of attribute tide_station_id.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def tide_station_id
  @tide_station_id
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def timezone
  @timezone
end

#ttypeObject (readonly)

Returns the value of attribute ttype.



15
16
17
# File 'lib/ndbc/station.rb', line 15

def ttype
  @ttype
end

Class Method Details

.allObject



9
10
11
# File 'lib/ndbc/station.rb', line 9

def all
  NDBC::StationTable.station_table_data.map { |data| new(data[:id].upcase, data) }
end

Instance Method Details

#continuous_winds_dataObject



50
51
52
53
54
# File 'lib/ndbc/station.rb', line 50

def continuous_winds_data
  @continuous_winds_data ||= parse_observation_response(
    get_data(NDBC.config[:urls][:observations] + id + ".cwind")
  )
end

#inspectObject



36
37
38
# File 'lib/ndbc/station.rb', line 36

def inspect
  "#{id} (lat: #{@location[:latitude]}, lon: #{@location[:longitude]})"
end

#latest_continuous_winds_dataObject



56
57
58
# File 'lib/ndbc/station.rb', line 56

def latest_continuous_winds_data
  latest_data(:continuous_winds_data)
end

#latest_spectral_wave_forecastsObject



76
77
78
# File 'lib/ndbc/station.rb', line 76

def latest_spectral_wave_forecasts
  latest_data(:spectral_wave_forecasts)
end

#latest_spectral_wave_summariesObject



66
67
68
# File 'lib/ndbc/station.rb', line 66

def latest_spectral_wave_summaries
  latest_data(:spectral_wave_summaries)
end

#latest_standard_meteorological_dataObject



46
47
48
# File 'lib/ndbc/station.rb', line 46

def latest_standard_meteorological_data
  latest_data(:standard_meteorological_data)
end

#respond_to_missing?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
107
108
109
110
# File 'lib/ndbc/station.rb', line 101

def respond_to_missing?(method_sym, include_private = false)
  case method_sym
  when :wdir, :wspd, :gst, :wvht, :dpd, :apd, :mwd, :pres, :atmp, :wtmp, :dewp, :vis, :ptdy,
       :tide, :dir, :spd, :gdr, :gsp, :gtime, :h0, :wwh, :wwp, :wwd, :steepness, :avp, :swh,
       :swp, :swd, :swd
    true
  else
    super
  end
end

#spectral_wave_forecastsObject



70
71
72
73
74
# File 'lib/ndbc/station.rb', line 70

def spectral_wave_forecasts
  @spectral_wave_forecasts ||= parse_prediction_response(
    get_data(NDBC.config[:urls][:predictions] + "multi_1.#{id}.bull")
  )
end

#spectral_wave_summariesObject



60
61
62
63
64
# File 'lib/ndbc/station.rb', line 60

def spectral_wave_summaries
  @spectral_wave_summaries ||= parse_observation_response(
    get_data(NDBC.config[:urls][:observations] + id + ".spec")
  )
end

#standard_meteorological_dataObject



40
41
42
43
44
# File 'lib/ndbc/station.rb', line 40

def standard_meteorological_data
  @standard_meteorological_data ||= parse_observation_response(
    get_data(NDBC.config[:urls][:observations] + id + ".txt")
  )
end