Skip to content

Commit

Permalink
Added RCAP::Info.
Browse files Browse the repository at this point in the history
  • Loading branch information
farrel committed Apr 16, 2013
1 parent 8d1dafe commit c4bc35a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rcap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
require 'rcap/cap_1_2/polygon'
require 'rcap/cap_1_2/geocode'
require 'rcap/cap_1_2/area'

require 'rcap/info'
require 'rcap/alert'
# Configuration
require 'rcap/config'
15 changes: 15 additions & 0 deletions lib/rcap/info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module RCAP
module Info

def self.from_h( alert, info_hash )
case alert.class::CAP_VERSION
when CAP_1_0::Alert::CAP_VERSION
CAP_1_0::Info.from_h( info_hash )
when CAP_1_1::Alert::CAP_VERSION
CAP_1_1::Info.from_h( info_hash )
else
CAP_1_2::Info.from_h( info_hash )
end
end
end
end
35 changes: 35 additions & 0 deletions spec/info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe( RCAP::Info ) do
describe( 'initialising' ) do
context( 'a CAP 1.2 info' ) do
let( :alert ) do
RCAP::CAP_1_2::Alert.new
end

let( :original_info ) do
RCAP::CAP_1_2::Info.new do |info|
info.event = "Event"
info.urgency = RCAP::CAP_1_2::Info::URGENCY_EXPECTED
info.severity = RCAP::CAP_1_2::Info::SEVERITY_SEVERE
info.certainty = RCAP::CAP_1_2::Info::CERTAINTY_LIKELY
end
end

shared_examples_for( 'the 1.2 Info object is initialised correctly' ) do
it( 'sets the event' ){ info.event.should == original_info.event }
it( 'sets the urgency' ){ info.urgency.should == original_info.urgency }
it( 'sets the severity' ){ info.severity.should == original_info.severity }
it( 'sets the certainty' ){ info.certainty.should == original_info.certainty }
end

context( 'from a Hash' ) do
let( :info ) do
RCAP::Info.from_h( alert, original_info.to_h )
end

it_should_behave_like( 'the 1.2 Info object is initialised correctly' )
end
end
end
end

0 comments on commit c4bc35a

Please sign in to comment.