Class: Nws::Api::Alerts::Alert

Inherits:
Object
  • Object
show all
Defined in:
lib/nws/api/alerts/alert.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#certaintyObject (readonly)

Returns the value of attribute certainty.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def certainty
  @certainty
end

#expiresObject (readonly)

Returns the value of attribute expires.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def expires
  @expires
end

#geometryObject (readonly)

Returns the value of attribute geometry.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def geometry
  @geometry
end

#instructionObject (readonly)

Returns the value of attribute instruction.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def instruction
  @instruction
end

#message_typeObject (readonly)

Returns the value of attribute message_type.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def message_type
  @message_type
end

#nws_idObject (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

#onsetObject (readonly)

Returns the value of attribute onset.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def onset
  @onset
end

#severityObject (readonly)

Returns the value of attribute severity.



9
10
11
# File 'lib/nws/api/alerts/alert.rb', line 9

def severity
  @severity
end

#urgencyObject (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

#attributesObject



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