Module: RCAP
- Defined in:
- lib/rcap/info.rb,
lib/rcap/alert.rb,
lib/rcap/config.rb,
lib/rcap/version.rb,
lib/rcap/base/area.rb,
lib/rcap/base/info.rb,
lib/rcap/utilities.rb,
lib/rcap/base/alert.rb,
lib/rcap/base/point.rb,
lib/rcap/base/circle.rb,
lib/rcap/base/geocode.rb,
lib/rcap/base/polygon.rb,
lib/rcap/cap_1_0/area.rb,
lib/rcap/cap_1_0/info.rb,
lib/rcap/cap_1_1/area.rb,
lib/rcap/cap_1_1/info.rb,
lib/rcap/cap_1_2/area.rb,
lib/rcap/cap_1_2/info.rb,
lib/rcap/base/resource.rb,
lib/rcap/cap_1_0/alert.rb,
lib/rcap/cap_1_0/point.rb,
lib/rcap/cap_1_1/alert.rb,
lib/rcap/cap_1_1/point.rb,
lib/rcap/cap_1_2/alert.rb,
lib/rcap/cap_1_2/point.rb,
lib/rcap/base/parameter.rb,
lib/rcap/cap_1_0/circle.rb,
lib/rcap/cap_1_1/circle.rb,
lib/rcap/cap_1_2/circle.rb,
lib/rcap/base/event_code.rb,
lib/rcap/cap_1_0/geocode.rb,
lib/rcap/cap_1_0/polygon.rb,
lib/rcap/cap_1_1/geocode.rb,
lib/rcap/cap_1_1/polygon.rb,
lib/rcap/cap_1_2/geocode.rb,
lib/rcap/cap_1_2/polygon.rb,
lib/rcap/cap_1_0/resource.rb,
lib/rcap/cap_1_1/resource.rb,
lib/rcap/cap_1_2/resource.rb,
lib/rcap/cap_1_0/parameter.rb,
lib/rcap/cap_1_1/parameter.rb,
lib/rcap/cap_1_2/parameter.rb,
lib/rcap/cap_1_0/event_code.rb,
lib/rcap/cap_1_1/event_code.rb,
lib/rcap/cap_1_2/event_code.rb
Defined Under Namespace
Modules: Alert, Base, CAP_1_0, CAP_1_1, CAP_1_2, Info
Constant Summary collapse
- XML_PRETTY_PRINTER =
REXML::Formatters::Pretty.new(2)
- RCAP_TIME_FORMAT =
'%Y-%m-%dT%H:%M:%S'- RCAP_ZONE_FORMAT =
'%+03i:00'- VERSION =
'2.7.0'
Class Method Summary collapse
-
.attribute_values_to_hash(*attribute_values) ⇒ Hash
Converts an array of key value pairs into a hash, excluding any value that is nil.
-
.format_lines_for_inspect(header, inspect_string) ⇒ String
Formats output for inspect.
-
.generate_identifier ⇒ String
Returns a randomly generated UUID string.
-
.parse_datetime(date) ⇒ String?
If the parameter is a string and not empty the datetime is parsed out of it, otherwise returns nil.
-
.strip_if_given(string) ⇒ String?
If the string given is not nil, String#strip is called otherwise nil is returned.
-
.to_f_if_given(number) ⇒ Float?
if the string is given, String#strip and then String#to_f are applied otherwise nil is returned.
-
.to_i_if_given(number) ⇒ Integer?
if the string is given, String#strip and then String#to_i are applied otherwise nil is returned.
-
.to_s_for_cap(object) ⇒ String
Calls #to_s_for_cap on the object it it responds to that otherwise just calls #to_s.
-
.unpack_if_given(list) ⇒ Array
If the list is given will split it with the separator parameter otherwise retun an empty array.
-
.xpath_first(xml_element, xpath, namespace) ⇒ REXML::Element?
Returns first descendent that matches the given XPath expression.
-
.xpath_match(xml_element, xpath, namespace) ⇒ Array<REXML::Element>
Returns all descendents that match the given XPath expression.
-
.xpath_text(xml_element, xpath, namespace) ⇒ String?
Returns the text of the first descendent that matches the given XPath expression.
Class Method Details
.attribute_values_to_hash(*attribute_values) ⇒ Hash
Converts an array of key value pairs into a hash, excluding any value that is nil.
74 75 76 |
# File 'lib/rcap/utilities.rb', line 74 def self.attribute_values_to_hash(*attribute_values) Hash[*attribute_values.reject { |_key, value| value.nil? }.flatten(1)] end |
.format_lines_for_inspect(header, inspect_string) ⇒ String
Formats output for inspect
59 60 61 62 63 64 65 |
# File 'lib/rcap/utilities.rb', line 59 def self.format_lines_for_inspect(header, inspect_string) max_line_length = inspect_string.lines.map { |line| line.strip.length }.max "\n." + '-' * (max_line_length + 2) + ".\n"\ '| ' + header.ljust(max_line_length) + " |\n"\ '|' + '-' * ( max_line_length + 2) + "|\n" + inspect_string.lines.map { |line| '| ' + line.strip.ljust(max_line_length) + ' |' }.join("\n") + "\n" \ "'" + '-' * ( max_line_length + 2) + "'\n" end |
.generate_identifier ⇒ String
Returns a randomly generated UUID string
7 8 9 |
# File 'lib/rcap/utilities.rb', line 7 def self.generate_identifier UUIDTools::UUID.random_create.to_s end |
.parse_datetime(date) ⇒ String?
If the parameter is a string and not empty the datetime is parsed out of it, otherwise returns nil.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rcap/utilities.rb', line 96 def self.parse_datetime(date) case date when String unless date.empty? DateTime.parse(date.strip) end when DateTime, Time, Date date.to_datetime end end |
.strip_if_given(string) ⇒ String?
If the string given is not nil, String#strip is called otherwise nil is returned
124 125 126 127 128 |
# File 'lib/rcap/utilities.rb', line 124 def self.strip_if_given(string) if string string.strip end end |
.to_f_if_given(number) ⇒ Float?
if the string is given, String#strip and then String#to_f are applied otherwise nil is returned.
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rcap/utilities.rb', line 135 def self.to_f_if_given(number) if number case number when String number.strip.to_f when Numeric number.to_f else number.to_s.strip.to_f end end end |
.to_i_if_given(number) ⇒ Integer?
if the string is given, String#strip and then String#to_i are applied otherwise nil is returned.
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rcap/utilities.rb', line 153 def self.to_i_if_given(number) if number case number when String number.strip.to_i when Numeric number.to_i else number.to_s.to_i end end end |
.to_s_for_cap(object) ⇒ String
Calls #to_s_for_cap on the object it it responds to that otherwise just calls #to_s
82 83 84 85 86 87 88 89 90 |
# File 'lib/rcap/utilities.rb', line 82 def self.to_s_for_cap(object) if object if object.respond_to?(:to_s_for_cap) object.to_s_for_cap else object.to_s end end end |
.unpack_if_given(list) ⇒ Array
If the list is given will split it with the separator parameter otherwise retun an empty array.
112 113 114 115 116 117 118 |
# File 'lib/rcap/utilities.rb', line 112 def self.unpack_if_given(list) if list list.unpack_cap_list else [] end end |
.xpath_first(xml_element, xpath, namespace) ⇒ REXML::Element?
Returns first descendent that matches the given XPath expression.
29 30 31 |
# File 'lib/rcap/utilities.rb', line 29 def self.xpath_first(xml_element, xpath, namespace) REXML::XPath.first(xml_element, xpath, 'cap' => namespace) end |
.xpath_match(xml_element, xpath, namespace) ⇒ Array<REXML::Element>
Returns all descendents that match the given XPath expression.
39 40 41 |
# File 'lib/rcap/utilities.rb', line 39 def self.xpath_match(xml_element, xpath, namespace) REXML::XPath.match(xml_element, xpath, 'cap' => namespace) end |
.xpath_text(xml_element, xpath, namespace) ⇒ String?
Returns the text of the first descendent that matches the given XPath expression.
18 19 20 21 |
# File 'lib/rcap/utilities.rb', line 18 def self.xpath_text(xml_element, xpath, namespace) element = xpath_first(xml_element, xpath, namespace) element.text.strip if element && element.text end |