noaa-alerts 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,10 @@ require "noaa-alerts/version"
2
2
 
3
3
  module Noaa
4
4
  class Alert
5
- attr_reader :description, :locations, :identifier, :effective_at, :expires_at, :event, :urgency, :severity, :headline, :sent_at
5
+ attr_reader :url, :description, :locations, :identifier, :effective_at, :expires_at, :event, :urgency, :severity, :headline, :sent_at
6
6
 
7
- def initialize(entry)
7
+ def initialize(url, entry)
8
+ @url = url || ""
8
9
  @description = ""
9
10
  @event = ""
10
11
  @urgency = ""
@@ -15,22 +16,23 @@ module Noaa
15
16
  @effective_at = nil
16
17
  @expires_at = nil
17
18
  @sent_at = nil
18
- handle_entry(entry)
19
+ handle_entry(entry) if entry
19
20
  end
20
21
 
21
22
  private
22
23
 
23
24
  def handle_entry(entry)
24
- @description = entry['info']['description']
25
- @event = entry['info']['event']
26
- @urgency= entry['info']['urgency']
27
- @severity = entry['info']['severity']
28
- @headline = entry['info']['headline']
29
- @locations = entry['info']['area']['areaDesc'].split('; ')
30
- @identifier = entry['identifier']
31
- @sent_at = Time.parse(entry['sent'])
32
- @effective_at = Time.parse(entry['info']['effective'])
33
- @expires_at = Time.parse(entry['info']['expires'])
25
+ info = entry.fetch('info')
26
+ @description = info.fetch('description')
27
+ @event = info.fetch('event')
28
+ @urgency= info.fetch('urgency')
29
+ @severity = info.fetch('severity')
30
+ @headline = info.fetch('headline')
31
+ @locations = info.fetch('area').fetch('areaDesc').split('; ')
32
+ @identifier = entry.fetch('identifier')
33
+ @sent_at = Time.parse(entry.fetch('sent'))
34
+ @effective_at = Time.parse(info.fetch('effective'))
35
+ @expires_at = Time.parse(info.fetch('expires'))
34
36
  end
35
37
  end
36
38
  end
@@ -24,7 +24,7 @@ module Noaa
24
24
  entries.each do |entry|
25
25
  item = HTTParty.get(entry['id'],
26
26
  format: :xml)['alert']
27
- @alerts << Noaa::Alert.new(item)
27
+ @alerts << Noaa::Alert.new(entry['id'], item)
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Noaa
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -20,6 +20,7 @@ describe Noaa, :vcr do
20
20
  describe Noaa::Alert do
21
21
  subject { Noaa::Client.new("ny").alerts.first }
22
22
 
23
+ its(:url) { should_not be_empty }
23
24
  its(:event) { should_not be_empty }
24
25
  its(:urgency) { should_not be_empty }
25
26
  its(:severity) { should_not be_empty }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noaa-alerts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-30 00:00:00.000000000 Z
12
+ date: 2012-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -137,4 +137,3 @@ specification_version: 3
137
137
  summary: Fetch and format feeds from the NOAA.
138
138
  test_files:
139
139
  - spec/noaa_alerts_spec.rb
140
- has_rdoc: