Class: Nws::Api::Alerts::Alert
- Inherits:
-
Object
- Object
- Nws::Api::Alerts::Alert
- Defined in:
- lib/nws/api/alerts/alert.rb
Instance Attribute Summary collapse
-
#certainty ⇒ Object
readonly
Returns the value of attribute certainty.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
-
#geometry ⇒ Object
readonly
Returns the value of attribute geometry.
-
#instruction ⇒ Object
readonly
Returns the value of attribute instruction.
-
#message_type ⇒ Object
readonly
Returns the value of attribute message_type.
-
#nws_id ⇒ Object
readonly
Returns the value of attribute nws_id.
-
#onset ⇒ Object
readonly
Returns the value of attribute onset.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#urgency ⇒ Object
readonly
Returns the value of attribute urgency.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(data) ⇒ Alert
constructor
A new instance of Alert.
Constructor Details
#initialize(data) ⇒ Alert
Returns a new instance of Alert.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nws/api/alerts/alert.rb', line 29 def initialize(data) if data['geometry'] @geometry = data['geometry']['coordinates'].first end properties = data['properties'] @nws_id = properties['id'] @onset = properties['onset'] @expires = properties['expires'] @message_type = properties['messageType'] @severity = properties['severity'] @certainty = properties['certainty'] @urgency = properties['urgency'] @instruction = properties['instruction'] end |
Instance Attribute Details
#certainty ⇒ Object (readonly)
Returns the value of attribute certainty.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def certainty @certainty end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def expires @expires end |
#geometry ⇒ Object (readonly)
Returns the value of attribute geometry.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def geometry @geometry end |
#instruction ⇒ Object (readonly)
Returns the value of attribute instruction.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def instruction @instruction end |
#message_type ⇒ Object (readonly)
Returns the value of attribute message_type.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def @message_type end |
#nws_id ⇒ Object (readonly)
Returns the value of attribute nws_id.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def nws_id @nws_id end |
#onset ⇒ Object (readonly)
Returns the value of attribute onset.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def onset @onset end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def severity @severity end |
#urgency ⇒ Object (readonly)
Returns the value of attribute urgency.
9 10 11 |
# File 'lib/nws/api/alerts/alert.rb', line 9 def urgency @urgency end |
Class Method Details
.from_api_response(client, parsed_response, alerts = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nws/api/alerts/alert.rb', line 11 def self.from_api_response(client, parsed_response, alerts = nil) alerts ||= AlertSet.new return alerts unless parsed_response['features'] parsed_response['features'].each do |alert_data| alerts << self.new(alert_data) end if parsed_response['pagination'] && parsed_response['pagination']['next'] next_uri = URI.parse(parsed_response['pagination']['next']) next_path = next_uri.to_s.gsub("#{next_uri.scheme}://#{next_uri.host}", '') self.from_api_response(client, client.fetch_raw_alerts(path: next_path), alerts) end return alerts end |
Instance Method Details
#attributes ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/nws/api/alerts/alert.rb', line 46 def attributes hsh = {} # Give back a hash of attributes suitable for persistance to a DB, for instance. instance_variables.map(&:to_s).map{|iv| iv.gsub('@', '')}.map{|att| hsh[att.to_sym] = self.send(att.to_sym)} hsh end |