class Gull::Alert

Gull represents an NWS/NOAA alert and provides the ability to fetch them from the public web service

Attributes

alert_type[RW]
area[RW]
certainty[RW]
effective_at[RW]
expires_at[RW]
geocode[RW]
id[RW]
polygon[RW]
published_at[RW]
severity[RW]
summary[RW]
title[RW]
updated_at[RW]
urgency[RW]
vtec[RW]

Public Class Methods

fetch(options = {}) click to toggle source
# File lib/gull/alert.rb, line 16
def self.fetch(options = {})
  client = Client.new options
  client.fetch
end
new() click to toggle source
# File lib/gull/alert.rb, line 12
def initialize
  self.geocode = Geocode.new
end

Public Instance Methods

parse(element) click to toggle source
# File lib/gull/alert.rb, line 21
def parse(element)
  parse_core_attributes element
  parse_times element
  parse_categories element

  parse_polygon element.xpath('cap:polygon').inner_text
  parse_geocode element.xpath('cap:geocode')
  parse_vtec element.xpath('cap:parameter')
end

Private Instance Methods

code_to_symbol(code) click to toggle source
# File lib/gull/alert.rb, line 77
def code_to_symbol(code)
  code.tr(' ', '_').downcase.to_sym
end
parse_categories(element) click to toggle source
# File lib/gull/alert.rb, line 54
def parse_categories(element)
  self.urgency = code_to_symbol element.xpath('cap:urgency').inner_text
  self.severity = code_to_symbol element.xpath('cap:severity').inner_text
  self.certainty = code_to_symbol element.xpath('cap:certainty').inner_text
end
parse_core_attributes(element) click to toggle source
# File lib/gull/alert.rb, line 33
def parse_core_attributes(element)
  self.id = element.css('id').inner_text
  self.title = element.css('title').inner_text
  self.summary = element.css('summary').inner_text
  self.link = parse_link element
  self.alert_type = element.xpath('cap:event').inner_text
  self.area = element.xpath('cap:areaDesc').inner_text
end
parse_geocode(element) click to toggle source
# File lib/gull/alert.rb, line 65
def parse_geocode(element)
  return if element.children.css('value').first.nil?

  geocode.fips6 = element.children.css('value').first.inner_text
  geocode.ugc = element.children.css('value').last.inner_text
end
parse_polygon(text) click to toggle source
# File lib/gull/alert.rb, line 60
def parse_polygon(text)
  return if text.empty?
  self.polygon = Polygon.new text
end
parse_times(element) click to toggle source
# File lib/gull/alert.rb, line 47
def parse_times(element)
  self.updated_at = Time.parse(element.css('updated').inner_text)
  self.published_at = Time.parse(element.css('published').inner_text)
  self.effective_at = Time.parse(element.xpath('cap:effective').inner_text)
  self.expires_at = Time.parse(element.xpath('cap:expires').inner_text)
end
parse_vtec(element) click to toggle source
# File lib/gull/alert.rb, line 72
def parse_vtec(element)
  value = element.children.css('value').inner_text
  self.vtec = value.empty? ? nil : value
end