Sha256: 4b84b19c622b8302b70a9081e460c743fd75f71a97e9b27f98e551496a1d7761
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
module RCAP module Alert XMLNS_KEY = "xmlns" YAML_CAP_VERSION_KEY = "CAP Version" JSON_CAP_VERSION_KEY = "cap_version" def self.from_xml( xml, namespace_key = XMLNS_KEY ) xml_document = REXML::Document.new( xml ) case xml_document.root.namespaces[ namespace_key ] when CAP_1_0::Alert::XMLNS CAP_1_0::Alert.from_xml_document( xml_document ) when CAP_1_1::Alert::XMLNS CAP_1_1::Alert.from_xml_document( xml_document ) else CAP_1_2::Alert.from_xml_document( xml_document ) end end def self.from_yaml( yaml ) yaml_data = YAML.load( yaml ) case yaml_data[ YAML_CAP_VERSION_KEY ] when CAP_1_0::Alert::CAP_VERSION CAP_1_0::Alert.from_yaml_data( yaml_data ) when CAP_1_1::Alert::CAP_VERSION CAP_1_1::Alert.from_yaml_data( yaml_data ) else CAP_1_2::Alert.from_yaml_data( yaml_data ) end end def self.from_json( json_string ) json_hash = JSON.parse( json_string ) self.from_h( json_hash ) end def self.from_h( hash ) # :nodoc: case hash[ JSON_CAP_VERSION_KEY ] when CAP_1_0::Alert::CAP_VERSION CAP_1_0::Alert.from_h( hash ) when CAP_1_1::Alert::CAP_VERSION CAP_1_1::Alert.from_h( hash ) else CAP_1_2::Alert.from_h( hash ) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rcap-1.1.1 | lib/rcap/alert.rb |
rcap-1.1.0 | lib/rcap/alert.rb |