rcap 2.4.1 → 2.7.3
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.
- checksums.yaml +5 -5
 - data/.ruby-version +1 -0
 - data/CHANGELOG.md +18 -0
 - data/README.md +1 -0
 - data/lib/rcap.rb +3 -1
 - data/lib/rcap/alert.rb +30 -29
 - data/lib/rcap/base/alert.rb +208 -205
 - data/lib/rcap/base/area.rb +95 -91
 - data/lib/rcap/base/circle.rb +45 -34
 - data/lib/rcap/base/event_code.rb +2 -0
 - data/lib/rcap/base/geocode.rb +2 -0
 - data/lib/rcap/base/info.rb +273 -272
 - data/lib/rcap/base/parameter.rb +29 -28
 - data/lib/rcap/base/point.rb +26 -24
 - data/lib/rcap/base/polygon.rb +43 -35
 - data/lib/rcap/base/resource.rb +65 -65
 - data/lib/rcap/cap_1_0/alert.rb +85 -86
 - data/lib/rcap/cap_1_0/area.rb +2 -2
 - data/lib/rcap/cap_1_0/circle.rb +2 -1
 - data/lib/rcap/cap_1_0/event_code.rb +3 -1
 - data/lib/rcap/cap_1_0/geocode.rb +3 -1
 - data/lib/rcap/cap_1_0/info.rb +3 -3
 - data/lib/rcap/cap_1_0/parameter.rb +13 -13
 - data/lib/rcap/cap_1_0/point.rb +2 -1
 - data/lib/rcap/cap_1_0/polygon.rb +3 -3
 - data/lib/rcap/cap_1_0/resource.rb +2 -3
 - data/lib/rcap/cap_1_1/alert.rb +6 -6
 - data/lib/rcap/cap_1_1/area.rb +2 -2
 - data/lib/rcap/cap_1_1/circle.rb +2 -1
 - data/lib/rcap/cap_1_1/event_code.rb +3 -1
 - data/lib/rcap/cap_1_1/geocode.rb +3 -1
 - data/lib/rcap/cap_1_1/info.rb +125 -132
 - data/lib/rcap/cap_1_1/parameter.rb +2 -3
 - data/lib/rcap/cap_1_1/point.rb +2 -1
 - data/lib/rcap/cap_1_1/polygon.rb +3 -3
 - data/lib/rcap/cap_1_1/resource.rb +37 -38
 - data/lib/rcap/cap_1_2/alert.rb +6 -6
 - data/lib/rcap/cap_1_2/area.rb +2 -2
 - data/lib/rcap/cap_1_2/circle.rb +2 -1
 - data/lib/rcap/cap_1_2/event_code.rb +3 -1
 - data/lib/rcap/cap_1_2/geocode.rb +3 -1
 - data/lib/rcap/cap_1_2/info.rb +120 -123
 - data/lib/rcap/cap_1_2/parameter.rb +2 -3
 - data/lib/rcap/cap_1_2/point.rb +2 -1
 - data/lib/rcap/cap_1_2/polygon.rb +4 -4
 - data/lib/rcap/cap_1_2/resource.rb +38 -38
 - data/lib/rcap/config.rb +5 -3
 - data/lib/rcap/custom_validators.rb +75 -78
 - data/lib/rcap/extensions/array.rb +3 -1
 - data/lib/rcap/extensions/date.rb +3 -1
 - data/lib/rcap/extensions/date_time.rb +5 -2
 - data/lib/rcap/extensions/float.rb +2 -0
 - data/lib/rcap/extensions/integer.rb +7 -0
 - data/lib/rcap/extensions/nil_class.rb +2 -0
 - data/lib/rcap/extensions/string.rb +6 -4
 - data/lib/rcap/extensions/time.rb +5 -3
 - data/lib/rcap/formatters/yaml.rb +5 -0
 - data/lib/rcap/info.rb +6 -5
 - data/lib/rcap/utilities.rb +27 -30
 - data/lib/rcap/validation.rb +22 -21
 - data/lib/rcap/version.rb +3 -1
 - data/rcap.gemspec +5 -5
 - data/spec/alert_spec.rb +141 -141
 - data/spec/cap_1_0/alert_spec.rb +92 -94
 - data/spec/cap_1_0/area_spec.rb +86 -86
 - data/spec/cap_1_0/circle_spec.rb +48 -39
 - data/spec/cap_1_0/event_code_spec.rb +15 -15
 - data/spec/cap_1_0/geocode_spec.rb +16 -16
 - data/spec/cap_1_0/info_spec.rb +175 -177
 - data/spec/cap_1_0/parameter_spec.rb +27 -27
 - data/spec/cap_1_0/point_spec.rb +18 -18
 - data/spec/cap_1_0/polygon_spec.rb +43 -41
 - data/spec/cap_1_0/resource_spec.rb +63 -64
 - data/spec/cap_1_1/alert_spec.rb +107 -109
 - data/spec/cap_1_1/area_spec.rb +90 -90
 - data/spec/cap_1_1/circle_spec.rb +43 -34
 - data/spec/cap_1_1/event_code_spec.rb +15 -16
 - data/spec/cap_1_1/geocode_spec.rb +16 -16
 - data/spec/cap_1_1/info_spec.rb +194 -196
 - data/spec/cap_1_1/parameter_spec.rb +17 -17
 - data/spec/cap_1_1/point_spec.rb +18 -18
 - data/spec/cap_1_1/polygon_spec.rb +43 -41
 - data/spec/cap_1_1/resource_spec.rb +106 -107
 - data/spec/cap_1_2/alert_spec.rb +98 -99
 - data/spec/cap_1_2/area_spec.rb +90 -90
 - data/spec/cap_1_2/circle_spec.rb +52 -43
 - data/spec/cap_1_2/event_code_spec.rb +19 -20
 - data/spec/cap_1_2/geocode_spec.rb +20 -20
 - data/spec/cap_1_2/info_spec.rb +196 -198
 - data/spec/cap_1_2/parameter_spec.rb +19 -19
 - data/spec/cap_1_2/point_spec.rb +21 -21
 - data/spec/cap_1_2/polygon_spec.rb +55 -47
 - data/spec/cap_1_2/resource_spec.rb +96 -97
 - data/spec/extensions_spec.rb +29 -29
 - data/spec/info_spec.rb +15 -15
 - data/spec/spec_helper.rb +3 -3
 - data/spec/validations_spec.rb +73 -73
 - metadata +12 -11
 - data/lib/rcap/extensions/fixnum.rb +0 -5
 
    
        data/lib/rcap/base/parameter.rb
    CHANGED
    
    | 
         @@ -1,46 +1,48 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module RCAP
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Base
         
     | 
| 
       3 
5 
     | 
    
         
             
                class Parameter
         
     | 
| 
       4 
6 
     | 
    
         
             
                  include Validation
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                  validates_presence_of( 
     | 
| 
      
 8 
     | 
    
         
            +
                  validates_presence_of(:name)
         
     | 
| 
       7 
9 
     | 
    
         | 
| 
       8 
10 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       9 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 11 
     | 
    
         
            +
                  attr_accessor(:name)
         
     | 
| 
       10 
12 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       11 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 13 
     | 
    
         
            +
                  attr_accessor(:value)
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                  XML_ELEMENT_NAME   =  
     | 
| 
       14 
     | 
    
         
            -
                  NAME_ELEMENT_NAME  =  
     | 
| 
       15 
     | 
    
         
            -
                  VALUE_ELEMENT_NAME =  
     | 
| 
      
 15 
     | 
    
         
            +
                  XML_ELEMENT_NAME   = 'parameter'
         
     | 
| 
      
 16 
     | 
    
         
            +
                  NAME_ELEMENT_NAME  = 'valueName'
         
     | 
| 
      
 17 
     | 
    
         
            +
                  VALUE_ELEMENT_NAME = 'value'
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                  XPATH       = "cap:#{ 
     | 
| 
       18 
     | 
    
         
            -
                  NAME_XPATH  = "cap:#{ 
     | 
| 
       19 
     | 
    
         
            -
                  VALUE_XPATH = "cap:#{ 
     | 
| 
      
 19 
     | 
    
         
            +
                  XPATH       = "cap:#{XML_ELEMENT_NAME}"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  NAME_XPATH  = "cap:#{NAME_ELEMENT_NAME}"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  VALUE_XPATH = "cap:#{VALUE_ELEMENT_NAME}"
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
       21 
23 
     | 
    
         
             
                  # @param [Hash] attributes
         
     | 
| 
       22 
24 
     | 
    
         
             
                  # @option attributes [Symbol] :name Parameter name
         
     | 
| 
       23 
25 
     | 
    
         
             
                  # @option attributes [Symbol] :value Parameter value
         
     | 
| 
       24 
26 
     | 
    
         
             
                  def initialize
         
     | 
| 
       25 
     | 
    
         
            -
                    yield( 
     | 
| 
      
 27 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       26 
28 
     | 
    
         
             
                  end
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
30 
     | 
    
         
             
                  # @return [REXML::Element]
         
     | 
| 
       29 
31 
     | 
    
         
             
                  def to_xml_element
         
     | 
| 
       30 
     | 
    
         
            -
                    xml_element = REXML::Element.new( 
     | 
| 
       31 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
       32 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
      
 32 
     | 
    
         
            +
                    xml_element = REXML::Element.new(self.class::XML_ELEMENT_NAME)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    xml_element.add_element(self.class::NAME_ELEMENT_NAME).add_text(@name)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    xml_element.add_element(self.class::VALUE_ELEMENT_NAME).add_text(@value)
         
     | 
| 
       33 
35 
     | 
    
         
             
                    xml_element
         
     | 
| 
       34 
36 
     | 
    
         
             
                  end
         
     | 
| 
       35 
37 
     | 
    
         | 
| 
       36 
38 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       37 
39 
     | 
    
         
             
                  def to_xml
         
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
      
 40 
     | 
    
         
            +
                    to_xml_element.to_s
         
     | 
| 
       39 
41 
     | 
    
         
             
                  end
         
     | 
| 
       40 
42 
     | 
    
         | 
| 
       41 
43 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       42 
44 
     | 
    
         
             
                  def inspect
         
     | 
| 
       43 
     | 
    
         
            -
                    "#{ 
     | 
| 
      
 45 
     | 
    
         
            +
                    "#{@name}: #{@value}"
         
     | 
| 
       44 
46 
     | 
    
         
             
                  end
         
     | 
| 
       45 
47 
     | 
    
         | 
| 
       46 
48 
     | 
    
         
             
                  # Returns a string representation of the parameter of the form
         
     | 
| 
         @@ -48,41 +50,40 @@ module RCAP 
     | 
|
| 
       48 
50 
     | 
    
         
             
                  #
         
     | 
| 
       49 
51 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       50 
52 
     | 
    
         
             
                  def to_s
         
     | 
| 
       51 
     | 
    
         
            -
                     
     | 
| 
      
 53 
     | 
    
         
            +
                    inspect
         
     | 
| 
       52 
54 
     | 
    
         
             
                  end
         
     | 
| 
       53 
55 
     | 
    
         | 
| 
       54 
56 
     | 
    
         
             
                  # Two parameters are equivalent if they have the same name and value.
         
     | 
| 
       55 
57 
     | 
    
         
             
                  #
         
     | 
| 
       56 
58 
     | 
    
         
             
                  # @param [Parameter] other
         
     | 
| 
       57 
59 
     | 
    
         
             
                  # @return [true, false]
         
     | 
| 
       58 
     | 
    
         
            -
                  def ==( 
     | 
| 
       59 
     | 
    
         
            -
                    [ 
     | 
| 
      
 60 
     | 
    
         
            +
                  def ==(other)
         
     | 
| 
      
 61 
     | 
    
         
            +
                    [@name, @value] == [other.name, other.value]
         
     | 
| 
       60 
62 
     | 
    
         
             
                  end
         
     | 
| 
       61 
63 
     | 
    
         | 
| 
       62 
64 
     | 
    
         
             
                  # @param [REXML::Element] parameter_xml_element
         
     | 
| 
       63 
65 
     | 
    
         
             
                  # @return [Parameter]
         
     | 
| 
       64 
     | 
    
         
            -
                  def self.from_xml_element( 
     | 
| 
       65 
     | 
    
         
            -
                     
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
                  def self.from_xml_element(parameter_xml_element)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    new do |parameter|
         
     | 
| 
      
 68 
     | 
    
         
            +
                      parameter.name  = RCAP.xpath_text(parameter_xml_element, self::NAME_XPATH, parameter.xmlns)
         
     | 
| 
      
 69 
     | 
    
         
            +
                      parameter.value = RCAP.xpath_text(parameter_xml_element, self::VALUE_XPATH, parameter.xmlns)
         
     | 
| 
       68 
70 
     | 
    
         
             
                    end
         
     | 
| 
       69 
71 
     | 
    
         
             
                  end
         
     | 
| 
       70 
72 
     | 
    
         | 
| 
       71 
73 
     | 
    
         
             
                  # @return [Hash]
         
     | 
| 
       72 
74 
     | 
    
         
             
                  def to_h
         
     | 
| 
       73 
     | 
    
         
            -
                    RCAP.attribute_values_to_hash( 
     | 
| 
      
 75 
     | 
    
         
            +
                    RCAP.attribute_values_to_hash([@name, @value])
         
     | 
| 
       74 
76 
     | 
    
         
             
                  end
         
     | 
| 
       75 
77 
     | 
    
         | 
| 
       76 
78 
     | 
    
         
             
                  # @param [Hash] hash
         
     | 
| 
       77 
79 
     | 
    
         
             
                  # @return [Parameter]
         
     | 
| 
       78 
     | 
    
         
            -
                  def self.from_h( 
     | 
| 
      
 80 
     | 
    
         
            +
                  def self.from_h(hash)
         
     | 
| 
       79 
81 
     | 
    
         
             
                    key = hash.keys.first
         
     | 
| 
       80 
     | 
    
         
            -
                     
     | 
| 
       81 
     | 
    
         
            -
                      parameter.name  = RCAP.strip_if_given( 
     | 
| 
       82 
     | 
    
         
            -
                      parameter.value = RCAP.strip_if_given( 
     | 
| 
      
 82 
     | 
    
         
            +
                    new do |parameter|
         
     | 
| 
      
 83 
     | 
    
         
            +
                      parameter.name  = RCAP.strip_if_given(key)
         
     | 
| 
      
 84 
     | 
    
         
            +
                      parameter.value = RCAP.strip_if_given(hash[key])
         
     | 
| 
       83 
85 
     | 
    
         
             
                    end
         
     | 
| 
       84 
86 
     | 
    
         
             
                  end
         
     | 
| 
       85 
87 
     | 
    
         
             
                end
         
     | 
| 
       86 
88 
     | 
    
         
             
              end
         
     | 
| 
       87 
89 
     | 
    
         
             
            end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
    
        data/lib/rcap/base/point.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module RCAP
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Base
         
     | 
| 
       3 
5 
     | 
    
         
             
                class Point
         
     | 
| 
         @@ -6,22 +8,22 @@ module RCAP 
     | 
|
| 
       6 
8 
     | 
    
         
             
                  MAX_LONGITUDE = 180
         
     | 
| 
       7 
9 
     | 
    
         
             
                  MIN_LONGITUDE = -180
         
     | 
| 
       8 
10 
     | 
    
         
             
                  MAX_LATTITUDE = 90
         
     | 
| 
       9 
     | 
    
         
            -
                  MIN_LATTITUDE= -90
         
     | 
| 
      
 11 
     | 
    
         
            +
                  MIN_LATTITUDE = -90
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
                  # @return [Numeric]
         
     | 
| 
       12 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 14 
     | 
    
         
            +
                  attr_accessor(:lattitude)
         
     | 
| 
       13 
15 
     | 
    
         
             
                  # @return [Numeric]
         
     | 
| 
       14 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 16 
     | 
    
         
            +
                  attr_accessor(:longitude)
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  validates_numericality_of( 
     | 
| 
       17 
     | 
    
         
            -
                  validates_inclusion_of( 
     | 
| 
       18 
     | 
    
         
            -
                  validates_inclusion_of( 
     | 
| 
      
 18 
     | 
    
         
            +
                  validates_numericality_of(:lattitude, :longitude)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  validates_inclusion_of(:lattitude, in: MIN_LATTITUDE..MAX_LATTITUDE)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  validates_inclusion_of(:longitude, in: MIN_LONGITUDE..MAX_LONGITUDE)
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
22 
     | 
    
         
             
                  # @param [Hash] attributes
         
     | 
| 
       21 
23 
     | 
    
         
             
                  # @option attributes [Numeric] :lattitude
         
     | 
| 
       22 
24 
     | 
    
         
             
                  # @option attributes [Numeric] :longitude
         
     | 
| 
       23 
25 
     | 
    
         
             
                  def initialize
         
     | 
| 
       24 
     | 
    
         
            -
                    yield( 
     | 
| 
      
 26 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       25 
27 
     | 
    
         
             
                  end
         
     | 
| 
       26 
28 
     | 
    
         | 
| 
       27 
29 
     | 
    
         
             
                  # Returns a string representation of the point of the form
         
     | 
| 
         @@ -29,20 +31,20 @@ module RCAP 
     | 
|
| 
       29 
31 
     | 
    
         
             
                  #
         
     | 
| 
       30 
32 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       31 
33 
     | 
    
         
             
                  def to_s
         
     | 
| 
       32 
     | 
    
         
            -
                    "#{ 
     | 
| 
      
 34 
     | 
    
         
            +
                    "#{lattitude},#{longitude}"
         
     | 
| 
       33 
35 
     | 
    
         
             
                  end
         
     | 
| 
       34 
36 
     | 
    
         | 
| 
       35 
37 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       36 
38 
     | 
    
         
             
                  def inspect
         
     | 
| 
       37 
     | 
    
         
            -
                    '('+ 
     | 
| 
      
 39 
     | 
    
         
            +
                    '(' + to_s + ')'
         
     | 
| 
       38 
40 
     | 
    
         
             
                  end
         
     | 
| 
       39 
41 
     | 
    
         | 
| 
       40 
42 
     | 
    
         
             
                  # Two points are equivalent if they have the same lattitude and longitude
         
     | 
| 
       41 
43 
     | 
    
         
             
                  #
         
     | 
| 
       42 
44 
     | 
    
         
             
                  # @param [Point] other
         
     | 
| 
       43 
45 
     | 
    
         
             
                  # @return [true, false]
         
     | 
| 
       44 
     | 
    
         
            -
                  def ==( 
     | 
| 
       45 
     | 
    
         
            -
                    [ 
     | 
| 
      
 46 
     | 
    
         
            +
                  def ==(other)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    [lattitude, longitude] == [other.lattitude, other.longitude]
         
     | 
| 
       46 
48 
     | 
    
         
             
                  end
         
     | 
| 
       47 
49 
     | 
    
         | 
| 
       48 
50 
     | 
    
         
             
                  LATTITUDE_KEY = 'lattitude'
         
     | 
| 
         @@ -50,16 +52,16 @@ module RCAP 
     | 
|
| 
       50 
52 
     | 
    
         | 
| 
       51 
53 
     | 
    
         
             
                  # @return [Hash]
         
     | 
| 
       52 
54 
     | 
    
         
             
                  def to_h
         
     | 
| 
       53 
     | 
    
         
            -
                    RCAP.attribute_values_to_hash( 
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
                    RCAP.attribute_values_to_hash([LATTITUDE_KEY, lattitude],
         
     | 
| 
      
 56 
     | 
    
         
            +
                                                  [LONGITUDE_KEY, longitude])
         
     | 
| 
       55 
57 
     | 
    
         
             
                  end
         
     | 
| 
       56 
58 
     | 
    
         | 
| 
       57 
59 
     | 
    
         
             
                  # @param [Hash] point_hash
         
     | 
| 
       58 
60 
     | 
    
         
             
                  # @return [Point]
         
     | 
| 
       59 
     | 
    
         
            -
                  def self.from_h( 
     | 
| 
       60 
     | 
    
         
            -
                     
     | 
| 
       61 
     | 
    
         
            -
                      point.lattitude = point_hash[ 
     | 
| 
       62 
     | 
    
         
            -
                      point.longitude = point_hash[ 
     | 
| 
      
 61 
     | 
    
         
            +
                  def self.from_h(point_hash)
         
     | 
| 
      
 62 
     | 
    
         
            +
                    new do |point|
         
     | 
| 
      
 63 
     | 
    
         
            +
                      point.lattitude = point_hash[LATTITUDE_KEY].to_f
         
     | 
| 
      
 64 
     | 
    
         
            +
                      point.longitude = point_hash[LONGITUDE_KEY].to_f
         
     | 
| 
       63 
65 
     | 
    
         
             
                    end
         
     | 
| 
       64 
66 
     | 
    
         
             
                  end
         
     | 
| 
       65 
67 
     | 
    
         | 
| 
         @@ -68,18 +70,18 @@ module RCAP 
     | 
|
| 
       68 
70 
     | 
    
         | 
| 
       69 
71 
     | 
    
         
             
                  # @return [Array(Numeric, Numeric)]
         
     | 
| 
       70 
72 
     | 
    
         
             
                  def to_a
         
     | 
| 
       71 
     | 
    
         
            -
                     
     | 
| 
       72 
     | 
    
         
            -
                      array[ 
     | 
| 
       73 
     | 
    
         
            -
                      array[ 
     | 
| 
      
 73 
     | 
    
         
            +
                    [].tap do |array|
         
     | 
| 
      
 74 
     | 
    
         
            +
                      array[LATTITUDE_INDEX] = lattitude
         
     | 
| 
      
 75 
     | 
    
         
            +
                      array[LONGITUDE_INDEX] = longitude
         
     | 
| 
       74 
76 
     | 
    
         
             
                    end
         
     | 
| 
       75 
77 
     | 
    
         
             
                  end
         
     | 
| 
       76 
78 
     | 
    
         | 
| 
       77 
79 
     | 
    
         
             
                  # @param [Array(Numeric, Numeric)] point_array
         
     | 
| 
       78 
80 
     | 
    
         
             
                  # @return [Point]
         
     | 
| 
       79 
     | 
    
         
            -
                  def self.from_a( 
     | 
| 
       80 
     | 
    
         
            -
                     
     | 
| 
       81 
     | 
    
         
            -
                      point.lattitude = point_array[ 
     | 
| 
       82 
     | 
    
         
            -
                      point.longitude = point_array[ 
     | 
| 
      
 81 
     | 
    
         
            +
                  def self.from_a(point_array)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    new do |point|
         
     | 
| 
      
 83 
     | 
    
         
            +
                      point.lattitude = point_array[LATTITUDE_INDEX].to_f
         
     | 
| 
      
 84 
     | 
    
         
            +
                      point.longitude = point_array[LONGITUDE_INDEX].to_f
         
     | 
| 
       83 
85 
     | 
    
         
             
                    end
         
     | 
| 
       84 
86 
     | 
    
         
             
                  end
         
     | 
| 
       85 
87 
     | 
    
         
             
                end
         
     | 
    
        data/lib/rcap/base/polygon.rb
    CHANGED
    
    | 
         @@ -1,56 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module RCAP
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Base
         
     | 
| 
       3 
5 
     | 
    
         
             
                class Polygon
         
     | 
| 
       4 
6 
     | 
    
         
             
                  include Validation
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
8 
     | 
    
         
             
                  # @return [Array<Point>] Collection of {Point} objects
         
     | 
| 
       7 
     | 
    
         
            -
                  attr_reader( 
     | 
| 
      
 9 
     | 
    
         
            +
                  attr_reader(:points)
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                  validates_collection_of( 
     | 
| 
       10 
     | 
    
         
            -
                  validates_length_of( 
     | 
| 
       11 
     | 
    
         
            -
                  validates_equality_of_first_and_last( 
     | 
| 
      
 11 
     | 
    
         
            +
                  validates_collection_of(:points)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  validates_length_of(:points, minimum: 3, allow_blank: true)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  validates_equality_of_first_and_last(:points, allow_empty: true)
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                  XML_ELEMENT_NAME = 'polygon'
         
     | 
| 
       14 
     | 
    
         
            -
                  XPATH            = "cap:#{ 
     | 
| 
      
 16 
     | 
    
         
            +
                  XPATH            = "cap:#{XML_ELEMENT_NAME}"
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
18 
     | 
    
         
             
                  # @param [Hash] attributes
         
     | 
| 
       17 
19 
     | 
    
         
             
                  # @option attributes [Array<Point>] :points Collection of {Point} objects
         
     | 
| 
       18 
20 
     | 
    
         
             
                  def initialize
         
     | 
| 
       19 
     | 
    
         
            -
                    @points = 
     | 
| 
       20 
     | 
    
         
            -
                    yield( 
     | 
| 
      
 21 
     | 
    
         
            +
                    @points = []
         
     | 
| 
      
 22 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       21 
23 
     | 
    
         
             
                  end
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
                  def add_point
         
     | 
| 
       24 
     | 
    
         
            -
                    point =  
     | 
| 
       25 
     | 
    
         
            -
                    yield( 
     | 
| 
       26 
     | 
    
         
            -
                     
     | 
| 
      
 26 
     | 
    
         
            +
                    point = point_class.new
         
     | 
| 
      
 27 
     | 
    
         
            +
                    yield(point) if block_given?
         
     | 
| 
      
 28 
     | 
    
         
            +
                    points << point
         
     | 
| 
       27 
29 
     | 
    
         
             
                    point
         
     | 
| 
       28 
30 
     | 
    
         
             
                  end
         
     | 
| 
       29 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
                  # Returns GeoJSON representation of the polygon
         
     | 
| 
      
 33 
     | 
    
         
            +
                  def to_geojson
         
     | 
| 
      
 34 
     | 
    
         
            +
                    coordinates = @points.map { |point| [point.longitude, point.lattitude] }
         
     | 
| 
      
 35 
     | 
    
         
            +
                    { 'type' => 'Polygon', 'coordinates' => [coordinates] }.to_json
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
       30 
38 
     | 
    
         
             
                  # Returns a string representation of the polygon of the form
         
     | 
| 
       31 
39 
     | 
    
         
             
                  #  points[0] points[1] points[2] ...
         
     | 
| 
       32 
40 
     | 
    
         
             
                  # where each point is formatted with Point#to_s
         
     | 
| 
       33 
41 
     | 
    
         
             
                  def to_s
         
     | 
| 
       34 
     | 
    
         
            -
                    @points.join( 
     | 
| 
      
 42 
     | 
    
         
            +
                    @points.join(' ')
         
     | 
| 
       35 
43 
     | 
    
         
             
                  end
         
     | 
| 
       36 
44 
     | 
    
         | 
| 
       37 
45 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       38 
46 
     | 
    
         
             
                  def inspect
         
     | 
| 
       39 
     | 
    
         
            -
                    "(#{ 
     | 
| 
      
 47 
     | 
    
         
            +
                    "(#{@points.map(&:inspect).join(', ')})"
         
     | 
| 
       40 
48 
     | 
    
         
             
                  end
         
     | 
| 
       41 
49 
     | 
    
         | 
| 
       42 
50 
     | 
    
         
             
                  # @return [REXML::Element]
         
     | 
| 
       43 
51 
     | 
    
         
             
                  def to_xml_element
         
     | 
| 
       44 
     | 
    
         
            -
                    xml_element = REXML::Element.new( 
     | 
| 
       45 
     | 
    
         
            -
                    xml_element.add_text( 
     | 
| 
      
 52 
     | 
    
         
            +
                    xml_element = REXML::Element.new(XML_ELEMENT_NAME)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    xml_element.add_text(to_s)
         
     | 
| 
       46 
54 
     | 
    
         
             
                    xml_element
         
     | 
| 
       47 
55 
     | 
    
         
             
                  end
         
     | 
| 
       48 
56 
     | 
    
         | 
| 
       49 
57 
     | 
    
         
             
                  # @return [Polygon]
         
     | 
| 
       50 
     | 
    
         
            -
                  def self.from_xml_element( 
     | 
| 
      
 58 
     | 
    
         
            +
                  def self.from_xml_element(polygon_xml_element)
         
     | 
| 
       51 
59 
     | 
    
         
             
                    if !polygon_xml_element.text.nil? && !polygon_xml_element.text.empty?
         
     | 
| 
       52 
     | 
    
         
            -
                      coordinates =  
     | 
| 
       53 
     | 
    
         
            -
                       
     | 
| 
      
 60 
     | 
    
         
            +
                      coordinates = parse_polygon_string(polygon_xml_element.text)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      new do |polygon|
         
     | 
| 
       54 
62 
     | 
    
         
             
                        coordinates.each do |lattitude, longitude|
         
     | 
| 
       55 
63 
     | 
    
         
             
                          polygon.add_point do |point|
         
     | 
| 
       56 
64 
     | 
    
         
             
                            point.lattitude = lattitude.to_f
         
     | 
| 
         @@ -59,31 +67,31 @@ module RCAP 
     | 
|
| 
       59 
67 
     | 
    
         
             
                        end
         
     | 
| 
       60 
68 
     | 
    
         
             
                      end
         
     | 
| 
       61 
69 
     | 
    
         
             
                    else
         
     | 
| 
       62 
     | 
    
         
            -
                       
     | 
| 
      
 70 
     | 
    
         
            +
                      new
         
     | 
| 
       63 
71 
     | 
    
         
             
                    end
         
     | 
| 
       64 
72 
     | 
    
         
             
                  end
         
     | 
| 
       65 
73 
     | 
    
         | 
| 
       66 
74 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       67 
75 
     | 
    
         
             
                  def to_xml
         
     | 
| 
       68 
     | 
    
         
            -
                     
     | 
| 
      
 76 
     | 
    
         
            +
                    to_xml_element.to_s
         
     | 
| 
       69 
77 
     | 
    
         
             
                  end
         
     | 
| 
       70 
78 
     | 
    
         | 
| 
       71 
79 
     | 
    
         
             
                  # Two polygons are equivalent if their collection of points is equivalent.
         
     | 
| 
       72 
80 
     | 
    
         
             
                  #
         
     | 
| 
       73 
81 
     | 
    
         
             
                  # @return [true,false]
         
     | 
| 
       74 
     | 
    
         
            -
                  def ==( 
     | 
| 
      
 82 
     | 
    
         
            +
                  def ==(other)
         
     | 
| 
       75 
83 
     | 
    
         
             
                    @points == other.points
         
     | 
| 
       76 
84 
     | 
    
         
             
                  end
         
     | 
| 
       77 
85 
     | 
    
         | 
| 
       78 
86 
     | 
    
         
             
                  # @return [Array<Array(Numeric,Numeric)>]
         
     | 
| 
       79 
     | 
    
         
            -
                  def self.parse_polygon_string( 
     | 
| 
       80 
     | 
    
         
            -
                    polygon_string.split( 
     | 
| 
      
 87 
     | 
    
         
            +
                  def self.parse_polygon_string(polygon_string)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    polygon_string.split(' ').map { |coordinate_string| coordinate_string.split(',').map(&:to_f) }
         
     | 
| 
       81 
89 
     | 
    
         
             
                  end
         
     | 
| 
       82 
90 
     | 
    
         | 
| 
       83 
91 
     | 
    
         
             
                  # @return [Polygon]
         
     | 
| 
       84 
     | 
    
         
            -
                  def self.from_yaml_data( 
     | 
| 
       85 
     | 
    
         
            -
                     
     | 
| 
       86 
     | 
    
         
            -
                      Array( 
     | 
| 
      
 92 
     | 
    
         
            +
                  def self.from_yaml_data(polygon_yaml_data)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    new do |polygon|
         
     | 
| 
      
 94 
     | 
    
         
            +
                      Array(polygon_yaml_data).each do |lattitude, longitude|
         
     | 
| 
       87 
95 
     | 
    
         
             
                        polygon.add_point do |point|
         
     | 
| 
       88 
96 
     | 
    
         
             
                          point.lattitude = lattitude.to_f
         
     | 
| 
       89 
97 
     | 
    
         
             
                          point.longitude = longitude.to_f
         
     | 
| 
         @@ -94,23 +102,23 @@ module RCAP 
     | 
|
| 
       94 
102 
     | 
    
         | 
| 
       95 
103 
     | 
    
         
             
                  # @return [Hash]
         
     | 
| 
       96 
104 
     | 
    
         
             
                  def to_yaml_data
         
     | 
| 
       97 
     | 
    
         
            -
                    @points.map{ |point| [ 
     | 
| 
      
 105 
     | 
    
         
            +
                    @points.map { |point| [point.lattitude, point.longitude] }
         
     | 
| 
       98 
106 
     | 
    
         
             
                  end
         
     | 
| 
       99 
107 
     | 
    
         | 
| 
       100 
108 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       101 
     | 
    
         
            -
                  def to_yaml( 
     | 
| 
       102 
     | 
    
         
            -
                     
     | 
| 
      
 109 
     | 
    
         
            +
                  def to_yaml(options = {})
         
     | 
| 
      
 110 
     | 
    
         
            +
                    to_yaml_data.to_yaml(options)
         
     | 
| 
       103 
111 
     | 
    
         
             
                  end
         
     | 
| 
       104 
112 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
                  POINTS_KEY 
     | 
| 
      
 113 
     | 
    
         
            +
                  POINTS_KEY = 'points'
         
     | 
| 
       106 
114 
     | 
    
         | 
| 
       107 
115 
     | 
    
         
             
                  # @return [Polygon]
         
     | 
| 
       108 
     | 
    
         
            -
                  def self.from_h( 
     | 
| 
       109 
     | 
    
         
            -
                     
     | 
| 
       110 
     | 
    
         
            -
                      Array( 
     | 
| 
      
 116 
     | 
    
         
            +
                  def self.from_h(polygon_hash)
         
     | 
| 
      
 117 
     | 
    
         
            +
                    new do |polygon|
         
     | 
| 
      
 118 
     | 
    
         
            +
                      Array(polygon_hash[POINTS_KEY]).each do |point_array|
         
     | 
| 
       111 
119 
     | 
    
         
             
                        polygon.add_point do |point|
         
     | 
| 
       112 
     | 
    
         
            -
                          point.lattitude = point_array[ 
     | 
| 
       113 
     | 
    
         
            -
                          point.longitude = point_array[ 
     | 
| 
      
 120 
     | 
    
         
            +
                          point.lattitude = point_array[Point::LATTITUDE_INDEX].to_f
         
     | 
| 
      
 121 
     | 
    
         
            +
                          point.longitude = point_array[Point::LONGITUDE_INDEX].to_f
         
     | 
| 
       114 
122 
     | 
    
         
             
                        end
         
     | 
| 
       115 
123 
     | 
    
         
             
                      end
         
     | 
| 
       116 
124 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -118,7 +126,7 @@ module RCAP 
     | 
|
| 
       118 
126 
     | 
    
         | 
| 
       119 
127 
     | 
    
         
             
                  # @return [Hash]
         
     | 
| 
       120 
128 
     | 
    
         
             
                  def to_h
         
     | 
| 
       121 
     | 
    
         
            -
                    { POINTS_KEY => @points.map 
     | 
| 
      
 129 
     | 
    
         
            +
                    { POINTS_KEY => @points.map(&:to_a) }
         
     | 
| 
       122 
130 
     | 
    
         
             
                  end
         
     | 
| 
       123 
131 
     | 
    
         
             
                end
         
     | 
| 
       124 
132 
     | 
    
         
             
              end
         
     | 
    
        data/lib/rcap/base/resource.rb
    CHANGED
    
    | 
         @@ -1,20 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module RCAP
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Base
         
     | 
| 
       3 
5 
     | 
    
         
             
                class Resource
         
     | 
| 
       4 
6 
     | 
    
         
             
                  include Validation
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
8 
     | 
    
         
             
                  # @return [String] Resource Description
         
     | 
| 
       7 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 9 
     | 
    
         
            +
                  attr_accessor(:resource_desc)
         
     | 
| 
       8 
10 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       9 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 11 
     | 
    
         
            +
                  attr_accessor(:mime_type)
         
     | 
| 
       10 
12 
     | 
    
         
             
                  # @return [Integer] Expressed in bytes
         
     | 
| 
       11 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 13 
     | 
    
         
            +
                  attr_accessor(:size)
         
     | 
| 
       12 
14 
     | 
    
         
             
                  # @return [String] Resource location
         
     | 
| 
       13 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 15 
     | 
    
         
            +
                  attr_accessor(:uri)
         
     | 
| 
       14 
16 
     | 
    
         
             
                  # @return [String] SHA-1 hash of contents of resource
         
     | 
| 
       15 
     | 
    
         
            -
                  attr_accessor( 
     | 
| 
      
 17 
     | 
    
         
            +
                  attr_accessor(:digest)
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                  validates_presence_of( 
     | 
| 
      
 19 
     | 
    
         
            +
                  validates_presence_of(:resource_desc)
         
     | 
| 
       18 
20 
     | 
    
         | 
| 
       19 
21 
     | 
    
         
             
                  XML_ELEMENT_NAME           = 'resource'
         
     | 
| 
       20 
22 
     | 
    
         
             
                  MIME_TYPE_ELEMENT_NAME     = 'mimeType'
         
     | 
| 
         @@ -23,12 +25,12 @@ module RCAP 
     | 
|
| 
       23 
25 
     | 
    
         
             
                  DIGEST_ELEMENT_NAME        = 'digest'
         
     | 
| 
       24 
26 
     | 
    
         
             
                  RESOURCE_DESC_ELEMENT_NAME = 'resourceDesc'
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                  XPATH               = "cap:#{ 
     | 
| 
       27 
     | 
    
         
            -
                  MIME_TYPE_XPATH     = "cap:#{ 
     | 
| 
       28 
     | 
    
         
            -
                  SIZE_XPATH          = "cap:#{ 
     | 
| 
       29 
     | 
    
         
            -
                  URI_XPATH           = "cap:#{ 
     | 
| 
       30 
     | 
    
         
            -
                  DIGEST_XPATH        = "cap:#{ 
     | 
| 
       31 
     | 
    
         
            -
                  RESOURCE_DESC_XPATH = "cap:#{ 
     | 
| 
      
 28 
     | 
    
         
            +
                  XPATH               = "cap:#{XML_ELEMENT_NAME}"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  MIME_TYPE_XPATH     = "cap:#{MIME_TYPE_ELEMENT_NAME}"
         
     | 
| 
      
 30 
     | 
    
         
            +
                  SIZE_XPATH          = "cap:#{SIZE_ELEMENT_NAME}"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  URI_XPATH           = "cap:#{URI_ELEMENT_NAME}"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  DIGEST_XPATH        = "cap:#{DIGEST_ELEMENT_NAME}"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  RESOURCE_DESC_XPATH = "cap:#{RESOURCE_DESC_ELEMENT_NAME}"
         
     | 
| 
       32 
34 
     | 
    
         | 
| 
       33 
35 
     | 
    
         
             
                  # @param [Hash{Symbol => Object}] attributes
         
     | 
| 
       34 
36 
     | 
    
         
             
                  # @option attributes [String] :mime_type
         
     | 
| 
         @@ -37,29 +39,29 @@ module RCAP 
     | 
|
| 
       37 
39 
     | 
    
         
             
                  # @option attributes [String] :digest
         
     | 
| 
       38 
40 
     | 
    
         
             
                  # @option attributes [String] :resource_desc
         
     | 
| 
       39 
41 
     | 
    
         
             
                  def initialize
         
     | 
| 
       40 
     | 
    
         
            -
                    yield( 
     | 
| 
      
 42 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       41 
43 
     | 
    
         
             
                  end
         
     | 
| 
       42 
44 
     | 
    
         | 
| 
       43 
45 
     | 
    
         
             
                  # @return [REXML::Element]
         
     | 
| 
       44 
46 
     | 
    
         
             
                  def to_xml_element
         
     | 
| 
       45 
     | 
    
         
            -
                    xml_element = REXML::Element.new( 
     | 
| 
       46 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
       47 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
       48 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
       49 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
       50 
     | 
    
         
            -
                    xml_element.add_element( 
     | 
| 
      
 47 
     | 
    
         
            +
                    xml_element = REXML::Element.new(XML_ELEMENT_NAME)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    xml_element.add_element(RESOURCE_DESC_ELEMENT_NAME).add_text(@resource_desc)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    xml_element.add_element(MIME_TYPE_ELEMENT_NAME).add_text(@mime_type) if @mime_type
         
     | 
| 
      
 50 
     | 
    
         
            +
                    xml_element.add_element(SIZE_ELEMENT_NAME).add_text(@size.to_s)      if @size
         
     | 
| 
      
 51 
     | 
    
         
            +
                    xml_element.add_element(URI_ELEMENT_NAME).add_text(@uri)             if @uri
         
     | 
| 
      
 52 
     | 
    
         
            +
                    xml_element.add_element(DIGEST_ELEMENT_NAME).add_text(@digest)       if @digest
         
     | 
| 
       51 
53 
     | 
    
         
             
                    xml_element
         
     | 
| 
       52 
54 
     | 
    
         
             
                  end
         
     | 
| 
       53 
55 
     | 
    
         | 
| 
       54 
56 
     | 
    
         
             
                  # @param [REXML::Element] resource_xml_element
         
     | 
| 
       55 
57 
     | 
    
         
             
                  # @return [Resource]
         
     | 
| 
       56 
     | 
    
         
            -
                  def self.from_xml_element( 
     | 
| 
       57 
     | 
    
         
            -
                    resource =  
     | 
| 
       58 
     | 
    
         
            -
                      resource.resource_desc = RCAP.xpath_text( 
     | 
| 
       59 
     | 
    
         
            -
                      resource.uri           = RCAP.xpath_text( 
     | 
| 
       60 
     | 
    
         
            -
                      resource.mime_type     = RCAP.xpath_text( 
     | 
| 
       61 
     | 
    
         
            -
                      resource.size          = RCAP.xpath_text( 
     | 
| 
       62 
     | 
    
         
            -
                      resource.digest        = RCAP.xpath_text( 
     | 
| 
      
 58 
     | 
    
         
            +
                  def self.from_xml_element(resource_xml_element)
         
     | 
| 
      
 59 
     | 
    
         
            +
                    resource = new do |resource|
         
     | 
| 
      
 60 
     | 
    
         
            +
                      resource.resource_desc = RCAP.xpath_text(resource_xml_element, RESOURCE_DESC_XPATH, resource.xmlns)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      resource.uri           = RCAP.xpath_text(resource_xml_element, URI_XPATH, resource.xmlns)
         
     | 
| 
      
 62 
     | 
    
         
            +
                      resource.mime_type     = RCAP.xpath_text(resource_xml_element, MIME_TYPE_XPATH, resource.xmlns)
         
     | 
| 
      
 63 
     | 
    
         
            +
                      resource.size          = RCAP.xpath_text(resource_xml_element, SIZE_XPATH, resource.xmlns).to_i
         
     | 
| 
      
 64 
     | 
    
         
            +
                      resource.digest        = RCAP.xpath_text(resource_xml_element, DIGEST_XPATH, resource.xmlns)
         
     | 
| 
       63 
65 
     | 
    
         
             
                    end
         
     | 
| 
       64 
66 
     | 
    
         
             
                  end
         
     | 
| 
       65 
67 
     | 
    
         | 
| 
         @@ -70,9 +72,9 @@ module RCAP 
     | 
|
| 
       70 
72 
     | 
    
         
             
                  # @return [nil,Array(Integer,String)]
         
     | 
| 
       71 
73 
     | 
    
         
             
                  def calculate_hash_and_size
         
     | 
| 
       72 
74 
     | 
    
         
             
                    if @deref_uri
         
     | 
| 
       73 
     | 
    
         
            -
                      @digest = Digest::SHA1.hexdigest( 
     | 
| 
      
 75 
     | 
    
         
            +
                      @digest = Digest::SHA1.hexdigest(@deref_uri)
         
     | 
| 
       74 
76 
     | 
    
         
             
                      @size = @deref_uri.bytesize
         
     | 
| 
       75 
     | 
    
         
            -
                      [ 
     | 
| 
      
 77 
     | 
    
         
            +
                      [@size, @digest]
         
     | 
| 
       76 
78 
     | 
    
         
             
                    end
         
     | 
| 
       77 
79 
     | 
    
         
             
                  end
         
     | 
| 
       78 
80 
     | 
    
         | 
| 
         @@ -80,25 +82,23 @@ module RCAP 
     | 
|
| 
       80 
82 
     | 
    
         
             
                  #
         
     | 
| 
       81 
83 
     | 
    
         
             
                  # @return [nil,String]
         
     | 
| 
       82 
84 
     | 
    
         
             
                  def decoded_deref_uri
         
     | 
| 
       83 
     | 
    
         
            -
                    Base64.decode64( 
     | 
| 
      
 85 
     | 
    
         
            +
                    Base64.decode64(@deref_uri) if @deref_uri
         
     | 
| 
       84 
86 
     | 
    
         
             
                  end
         
     | 
| 
       85 
87 
     | 
    
         | 
| 
       86 
88 
     | 
    
         
             
                  # If size is defined returns the size in kilobytes
         
     | 
| 
       87 
89 
     | 
    
         
             
                  # @return [Float]
         
     | 
| 
       88 
90 
     | 
    
         
             
                  def size_in_kb
         
     | 
| 
       89 
     | 
    
         
            -
                    if @size
         
     | 
| 
       90 
     | 
    
         
            -
                      @size.to_f/1024
         
     | 
| 
       91 
     | 
    
         
            -
                    end
         
     | 
| 
      
 91 
     | 
    
         
            +
                    @size.to_f / 1024 if @size
         
     | 
| 
       92 
92 
     | 
    
         
             
                  end
         
     | 
| 
       93 
93 
     | 
    
         | 
| 
       94 
94 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       95 
95 
     | 
    
         
             
                  def to_xml
         
     | 
| 
       96 
     | 
    
         
            -
                     
     | 
| 
      
 96 
     | 
    
         
            +
                    to_xml_element.to_s
         
     | 
| 
       97 
97 
     | 
    
         
             
                  end
         
     | 
| 
       98 
98 
     | 
    
         | 
| 
       99 
99 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       100 
100 
     | 
    
         
             
                  def inspect
         
     | 
| 
       101 
     | 
    
         
            -
                    [ 
     | 
| 
      
 101 
     | 
    
         
            +
                    [@resource_desc, @uri, @mime_type, @size ? format('%.1fKB', size_in_kb) : nil].compact.join(' - ')
         
     | 
| 
       102 
102 
     | 
    
         
             
                  end
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
       104 
104 
     | 
    
         
             
                  # Returns a string representation of the resource of the form
         
     | 
| 
         @@ -109,35 +109,35 @@ module RCAP 
     | 
|
| 
       109 
109 
     | 
    
         
             
                    @resource_desc
         
     | 
| 
       110 
110 
     | 
    
         
             
                  end
         
     | 
| 
       111 
111 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
                  RESOURCE_DESC_YAML =  
     | 
| 
       113 
     | 
    
         
            -
                  URI_YAML           =  
     | 
| 
       114 
     | 
    
         
            -
                  MIME_TYPE_YAML     =  
     | 
| 
       115 
     | 
    
         
            -
                  SIZE_YAML          =  
     | 
| 
       116 
     | 
    
         
            -
                  DIGEST_YAML        =  
     | 
| 
      
 112 
     | 
    
         
            +
                  RESOURCE_DESC_YAML = 'Resource Description'
         
     | 
| 
      
 113 
     | 
    
         
            +
                  URI_YAML           = 'URI'
         
     | 
| 
      
 114 
     | 
    
         
            +
                  MIME_TYPE_YAML     = 'Mime Type'
         
     | 
| 
      
 115 
     | 
    
         
            +
                  SIZE_YAML          = 'Size'
         
     | 
| 
      
 116 
     | 
    
         
            +
                  DIGEST_YAML        = 'Digest'
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                  def to_yaml_data
         
     | 
| 
       119 
     | 
    
         
            -
                    RCAP.attribute_values_to_hash( 
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 119 
     | 
    
         
            +
                    RCAP.attribute_values_to_hash([RESOURCE_DESC_YAML, @resource_desc],
         
     | 
| 
      
 120 
     | 
    
         
            +
                                                  [URI_YAML,           @uri],
         
     | 
| 
      
 121 
     | 
    
         
            +
                                                  [MIME_TYPE_YAML,     @mime_type],
         
     | 
| 
      
 122 
     | 
    
         
            +
                                                  [SIZE_YAML,          @size],
         
     | 
| 
      
 123 
     | 
    
         
            +
                                                  [DIGEST_YAML,        @digest])
         
     | 
| 
       124 
124 
     | 
    
         
             
                  end
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
       126 
126 
     | 
    
         
             
                  # @param [Hash] options
         
     | 
| 
       127 
127 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       128 
     | 
    
         
            -
                  def to_yaml( 
     | 
| 
       129 
     | 
    
         
            -
                     
     | 
| 
      
 128 
     | 
    
         
            +
                  def to_yaml(options = {})
         
     | 
| 
      
 129 
     | 
    
         
            +
                    to_yaml_data.to_yaml(options)
         
     | 
| 
       130 
130 
     | 
    
         
             
                  end
         
     | 
| 
       131 
131 
     | 
    
         | 
| 
       132 
132 
     | 
    
         
             
                  # @param [Hash] resource_yaml_data
         
     | 
| 
       133 
133 
     | 
    
         
             
                  # @return [Resource]
         
     | 
| 
       134 
     | 
    
         
            -
                  def self.from_yaml_data( 
     | 
| 
       135 
     | 
    
         
            -
                     
     | 
| 
       136 
     | 
    
         
            -
                      resource.resource_desc = resource_yaml_data[ 
     | 
| 
       137 
     | 
    
         
            -
                      resource.uri           = resource_yaml_data[ 
     | 
| 
       138 
     | 
    
         
            -
                      resource.mime_type     = resource_yaml_data[ 
     | 
| 
       139 
     | 
    
         
            -
                      resource.size          = resource_yaml_data[ 
     | 
| 
       140 
     | 
    
         
            -
                      resource.digest        = resource_yaml_data[ 
     | 
| 
      
 134 
     | 
    
         
            +
                  def self.from_yaml_data(resource_yaml_data)
         
     | 
| 
      
 135 
     | 
    
         
            +
                    new do |resource|
         
     | 
| 
      
 136 
     | 
    
         
            +
                      resource.resource_desc = resource_yaml_data[RESOURCE_DESC_YAML]
         
     | 
| 
      
 137 
     | 
    
         
            +
                      resource.uri           = resource_yaml_data[URI_YAML]
         
     | 
| 
      
 138 
     | 
    
         
            +
                      resource.mime_type     = resource_yaml_data[MIME_TYPE_YAML]
         
     | 
| 
      
 139 
     | 
    
         
            +
                      resource.size          = resource_yaml_data[SIZE_YAML]
         
     | 
| 
      
 140 
     | 
    
         
            +
                      resource.digest        = resource_yaml_data[DIGEST_YAML]
         
     | 
| 
       141 
141 
     | 
    
         
             
                    end
         
     | 
| 
       142 
142 
     | 
    
         
             
                  end
         
     | 
| 
       143 
143 
     | 
    
         | 
| 
         @@ -149,22 +149,22 @@ module RCAP 
     | 
|
| 
       149 
149 
     | 
    
         | 
| 
       150 
150 
     | 
    
         
             
                  # @return [Hash]
         
     | 
| 
       151 
151 
     | 
    
         
             
                  def to_h
         
     | 
| 
       152 
     | 
    
         
            -
                    RCAP.attribute_values_to_hash( 
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
      
 152 
     | 
    
         
            +
                    RCAP.attribute_values_to_hash([RESOURCE_DESC_KEY, @resource_desc],
         
     | 
| 
      
 153 
     | 
    
         
            +
                                                  [URI_KEY,           @uri],
         
     | 
| 
      
 154 
     | 
    
         
            +
                                                  [MIME_TYPE_KEY,     @mime_type],
         
     | 
| 
      
 155 
     | 
    
         
            +
                                                  [SIZE_KEY,          @size],
         
     | 
| 
      
 156 
     | 
    
         
            +
                                                  [DIGEST_KEY,        @digest])
         
     | 
| 
       157 
157 
     | 
    
         
             
                  end
         
     | 
| 
       158 
158 
     | 
    
         | 
| 
       159 
159 
     | 
    
         
             
                  # @param [Hash] resource_hash
         
     | 
| 
       160 
160 
     | 
    
         
             
                  # @return [Resource]
         
     | 
| 
       161 
     | 
    
         
            -
                  def self.from_h( 
     | 
| 
       162 
     | 
    
         
            -
                     
     | 
| 
       163 
     | 
    
         
            -
                      resource.resource_desc = RCAP.strip_if_given( 
     | 
| 
       164 
     | 
    
         
            -
                      resource.uri           = RCAP.strip_if_given( 
     | 
| 
       165 
     | 
    
         
            -
                      resource.mime_type     = RCAP.strip_if_given( 
     | 
| 
       166 
     | 
    
         
            -
                      resource.size          = RCAP.to_i_if_given( 
     | 
| 
       167 
     | 
    
         
            -
                      resource.digest        = RCAP.strip_if_given( 
     | 
| 
      
 161 
     | 
    
         
            +
                  def self.from_h(resource_hash)
         
     | 
| 
      
 162 
     | 
    
         
            +
                    new do |resource|
         
     | 
| 
      
 163 
     | 
    
         
            +
                      resource.resource_desc = RCAP.strip_if_given(resource_hash[RESOURCE_DESC_KEY])
         
     | 
| 
      
 164 
     | 
    
         
            +
                      resource.uri           = RCAP.strip_if_given(resource_hash[URI_KEY])
         
     | 
| 
      
 165 
     | 
    
         
            +
                      resource.mime_type     = RCAP.strip_if_given(resource_hash[MIME_TYPE_KEY])
         
     | 
| 
      
 166 
     | 
    
         
            +
                      resource.size          = RCAP.to_i_if_given(resource_hash[SIZE_KEY])
         
     | 
| 
      
 167 
     | 
    
         
            +
                      resource.digest        = RCAP.strip_if_given(resource_hash[DIGEST_KEY])
         
     | 
| 
       168 
168 
     | 
    
         
             
                    end
         
     | 
| 
       169 
169 
     | 
    
         
             
                  end
         
     | 
| 
       170 
170 
     | 
    
         
             
                end
         
     |