rcap 1.3.1 → 2.0.0

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.
Files changed (88) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/README.md +78 -151
  3. data/Rakefile +1 -1
  4. data/lib/rcap/alert.rb +2 -2
  5. data/lib/rcap/base/alert.rb +446 -0
  6. data/lib/rcap/base/area.rb +228 -0
  7. data/lib/rcap/base/circle.rb +121 -0
  8. data/lib/rcap/base/event_code.rb +6 -0
  9. data/lib/rcap/base/geocode.rb +6 -0
  10. data/lib/rcap/base/info.rb +498 -0
  11. data/lib/rcap/base/parameter.rb +88 -0
  12. data/lib/rcap/base/point.rb +87 -0
  13. data/lib/rcap/base/polygon.rb +120 -0
  14. data/lib/rcap/base/resource.rb +168 -0
  15. data/lib/rcap/cap_1_0/alert.rb +59 -342
  16. data/lib/rcap/cap_1_0/area.rb +13 -188
  17. data/lib/rcap/cap_1_0/circle.rb +2 -100
  18. data/lib/rcap/cap_1_0/event_code.rb +8 -3
  19. data/lib/rcap/cap_1_0/geocode.rb +8 -3
  20. data/lib/rcap/cap_1_0/info.rb +16 -468
  21. data/lib/rcap/cap_1_0/parameter.rb +9 -67
  22. data/lib/rcap/cap_1_0/point.rb +2 -61
  23. data/lib/rcap/cap_1_0/polygon.rb +5 -95
  24. data/lib/rcap/cap_1_0/resource.rb +4 -144
  25. data/lib/rcap/cap_1_1/alert.rb +7 -412
  26. data/lib/rcap/cap_1_1/area.rb +13 -188
  27. data/lib/rcap/cap_1_1/circle.rb +2 -100
  28. data/lib/rcap/cap_1_1/event_code.rb +8 -3
  29. data/lib/rcap/cap_1_1/geocode.rb +7 -3
  30. data/lib/rcap/cap_1_1/info.rb +127 -386
  31. data/lib/rcap/cap_1_1/parameter.rb +4 -76
  32. data/lib/rcap/cap_1_1/point.rb +2 -61
  33. data/lib/rcap/cap_1_1/polygon.rb +5 -95
  34. data/lib/rcap/cap_1_1/resource.rb +37 -143
  35. data/lib/rcap/cap_1_2/alert.rb +8 -413
  36. data/lib/rcap/cap_1_2/area.rb +13 -188
  37. data/lib/rcap/cap_1_2/circle.rb +2 -100
  38. data/lib/rcap/cap_1_2/event_code.rb +8 -3
  39. data/lib/rcap/cap_1_2/geocode.rb +8 -3
  40. data/lib/rcap/cap_1_2/info.rb +132 -419
  41. data/lib/rcap/cap_1_2/parameter.rb +4 -76
  42. data/lib/rcap/cap_1_2/point.rb +2 -61
  43. data/lib/rcap/cap_1_2/polygon.rb +5 -92
  44. data/lib/rcap/cap_1_2/resource.rb +31 -134
  45. data/lib/rcap/config.rb +3 -0
  46. data/lib/{extensions → rcap/extensions}/array.rb +1 -1
  47. data/lib/rcap/extensions/date.rb +11 -0
  48. data/lib/{extensions → rcap/extensions}/date_time.rb +2 -5
  49. data/lib/{extensions → rcap/extensions}/string.rb +1 -1
  50. data/lib/{extensions → rcap/extensions}/time.rb +2 -4
  51. data/lib/rcap/utilities.rb +11 -11
  52. data/lib/rcap/validations.rb +7 -2
  53. data/lib/rcap/version.rb +1 -1
  54. data/lib/rcap.rb +21 -4
  55. data/spec/alert_spec.rb +69 -37
  56. data/spec/cap_1_0/alert_spec.rb +46 -61
  57. data/spec/cap_1_0/area_spec.rb +77 -37
  58. data/spec/cap_1_0/circle_spec.rb +26 -6
  59. data/spec/cap_1_0/event_code_spec.rb +10 -3
  60. data/spec/cap_1_0/geocode_spec.rb +11 -4
  61. data/spec/cap_1_0/info_spec.rb +74 -77
  62. data/spec/cap_1_0/parameter_spec.rb +18 -5
  63. data/spec/cap_1_0/point_spec.rb +9 -2
  64. data/spec/cap_1_0/polygon_spec.rb +52 -9
  65. data/spec/cap_1_0/resource_spec.rb +28 -21
  66. data/spec/cap_1_1/alert_spec.rb +47 -60
  67. data/spec/cap_1_1/area_spec.rb +66 -43
  68. data/spec/cap_1_1/circle_spec.rb +29 -6
  69. data/spec/cap_1_1/event_code_spec.rb +11 -3
  70. data/spec/cap_1_1/geocode_spec.rb +11 -3
  71. data/spec/cap_1_1/info_spec.rb +262 -118
  72. data/spec/cap_1_1/parameter_spec.rb +12 -3
  73. data/spec/cap_1_1/point_spec.rb +8 -2
  74. data/spec/cap_1_1/polygon_spec.rb +57 -18
  75. data/spec/cap_1_1/resource_spec.rb +70 -20
  76. data/spec/cap_1_2/alert_spec.rb +97 -110
  77. data/spec/cap_1_2/area_spec.rb +59 -41
  78. data/spec/cap_1_2/circle_spec.rb +15 -8
  79. data/spec/cap_1_2/event_code_spec.rb +11 -3
  80. data/spec/cap_1_2/geocode_spec.rb +11 -3
  81. data/spec/cap_1_2/info_spec.rb +266 -119
  82. data/spec/cap_1_2/parameter_spec.rb +11 -3
  83. data/spec/cap_1_2/point_spec.rb +10 -3
  84. data/spec/cap_1_2/polygon_spec.rb +25 -10
  85. data/spec/cap_1_2/resource_spec.rb +33 -28
  86. data/spec/{utilities_spec.rb → extensions_spec.rb} +0 -0
  87. data/spec/validations_spec.rb +18 -2
  88. metadata +20 -46
@@ -1,86 +1,14 @@
1
1
  module RCAP
2
2
  module CAP_1_1
3
+
3
4
  # A Parameter object is valid if
4
5
  # * it has a name
5
6
  # * it has a value
6
- class Parameter
7
- include Validation
8
-
9
- validates_presence_of( :name, :value )
7
+ class Parameter < RCAP::Base::Parameter
10
8
 
11
9
  # @return [String]
12
- attr_accessor( :name )
13
- # @return [String]
14
- attr_accessor( :value )
15
-
16
- XML_ELEMENT_NAME = "parameter"
17
- NAME_ELEMENT_NAME = "valueName"
18
- VALUE_ELEMENT_NAME = "value"
19
-
20
- XPATH = "cap:#{ XML_ELEMENT_NAME }"
21
- NAME_XPATH = "cap:#{ NAME_ELEMENT_NAME }"
22
- VALUE_XPATH = "cap:#{ VALUE_ELEMENT_NAME }"
23
-
24
- # @param [Hash] attributes
25
- # @option attributes [Symbol] :name Parameter name
26
- # @option attributes [Symbol] :value Parameter value
27
- def initialize( attributes = {} )
28
- @name = attributes[ :name ]
29
- @value = attributes[ :value ]
30
- end
31
-
32
- # @return [REXML::Element]
33
- def to_xml_element
34
- xml_element = REXML::Element.new( self.class::XML_ELEMENT_NAME )
35
- xml_element.add_element( self.class::NAME_ELEMENT_NAME ).add_text( @name )
36
- xml_element.add_element( self.class::VALUE_ELEMENT_NAME ).add_text( @value )
37
- xml_element
38
- end
39
-
40
- # @return [String]
41
- def to_xml
42
- self.to_xml_element.to_s
43
- end
44
-
45
- # @return [String]
46
- def inspect
47
- "#{ @name }: #{ @value }"
48
- end
49
-
50
- # Returns a string representation of the parameter of the form
51
- # name: value
52
- #
53
- # @return [String]
54
- def to_s
55
- self.inspect
56
- end
57
-
58
- # @param [REXML::Element] parameter_xml_element
59
- # @return [Parameter]
60
- def self.from_xml_element( parameter_xml_element ) # :nodoc:
61
- self.new( :name => RCAP.xpath_text( parameter_xml_element, self::NAME_XPATH, Alert::XMLNS ),
62
- :value => RCAP.xpath_text( parameter_xml_element, self::VALUE_XPATH, Alert::XMLNS ))
63
- end
64
-
65
- # Two parameters are equivalent if they have the same name and value.
66
- #
67
- # @param [Parameter] other
68
- # @return [true, false]
69
- def ==( other )
70
- [ @name, @value ] == [ other.name, other.value ]
71
- end
72
-
73
- # @return [Hash]
74
- def to_h
75
- RCAP.attribute_values_to_hash(
76
- [ @name, @value ])
77
- end
78
-
79
- # @param [Hash] hash
80
- # @return [Parameter]
81
- def self.from_h( hash )
82
- key = hash.keys.first
83
- self.new( :name => key, :value => hash[ key ])
10
+ def xmlns
11
+ Alert::XMLNS
84
12
  end
85
13
  end
86
14
  end
@@ -1,69 +1,10 @@
1
1
  module RCAP
2
2
  module CAP_1_1
3
+
3
4
  # A Point object is valid if
4
5
  # * it has a lattitude within the minimum and maximum lattitude values
5
6
  # * it has a longitude within the minimum and maximum longitude values
6
- class Point
7
- include Validation
8
-
9
- MAX_LONGITUDE = 180
10
- MIN_LONGITUDE = -180
11
- MAX_LATTITUDE = 90
12
- MIN_LATTITUDE = -90
13
-
14
- # @return [Numeric]
15
- attr_accessor( :lattitude )
16
- # @return [Numeric]
17
- attr_accessor( :longitude )
18
-
19
- validates_numericality_of( :lattitude, :longitude )
20
- validates_inclusion_of( :lattitude, :in => MIN_LATTITUDE..MAX_LATTITUDE )
21
- validates_inclusion_of( :longitude, :in => MIN_LONGITUDE..MAX_LONGITUDE)
22
-
23
- # @param [Hash] attributes
24
- # @option attributes [Numeric] :lattitude
25
- # @option attributes [Numeric] :longitude
26
- def initialize( attributes = {} )
27
- @lattitude = attributes[ :lattitude ]
28
- @longitude = attributes[ :longitude ]
29
- end
30
-
31
- # Returns a string representation of the point of the form
32
- # lattitude,longitude
33
- #
34
- # @return [String]
35
- def to_s
36
- "#{ @lattitude },#{ @longitude }"
37
- end
38
-
39
- # @return [String]
40
- def inspect
41
- '('+self.to_s+')'
42
- end
43
-
44
- # Two points are equivalent if they have the same lattitude and longitude
45
- #
46
- # @param [Point] other
47
- # @return [true, false]
48
- def ==( other )
49
- [ @lattitude, @longitude ] == [ other.lattitude, other.longitude ]
50
- end
51
-
52
- LATTITUDE_KEY = 'lattitude'
53
- LONGITUDE_KEY = 'longitude'
54
-
55
- # @return [Hash]
56
- def to_h
57
- RCAP.attribute_values_to_hash(
58
- [ LATTITUDE_KEY, @lattitude ],
59
- [ LONGITUDE_KEY, @longitude ])
60
- end
61
-
62
- # @param [Hash] point_hash
63
- # @return [Point]
64
- def self.from_h( point_hash )
65
- self.new( :lattitude => point_hash[ LATTITUDE_KEY ], :longitude => point_hash[ LONGITUDE_KEY ])
66
- end
7
+ class Point < RCAP::Base::Point
67
8
  end
68
9
  end
69
10
  end
@@ -1,104 +1,14 @@
1
1
  module RCAP
2
2
  module CAP_1_1
3
+
3
4
  # A Polygon object is valid if
4
5
  # * it has a minimum of three points
5
6
  # * each Point object in the points collection is valid
6
- class Polygon
7
- include Validation
8
-
9
- # @return [Array<Point>] Collection of {Point} objects.
10
- attr_reader( :points )
11
-
12
- validates_collection_of( :points )
13
- validates_length_of( :points, :minimum => 3 )
14
- validates_equality_of_first_and_last( :points )
15
-
16
- XML_ELEMENT_NAME = 'polygon'
17
- XPATH = "cap:#{ XML_ELEMENT_NAME }"
18
-
19
- # @param [Hash] attributes
20
- # @option attributes [Array<Point>] :points Collection of {Point} objects
21
- def initialize( attributes = {})
22
- @points = Array( attributes[ :points ])
23
- end
24
-
25
- # Creates a new Point object and adds it to the points array.
26
- #
27
- # @see Point#initialize
28
- def add_point( point_attributes = {})
29
- point = Point.new( point_attributes )
30
- @points << point
31
- point
32
- end
33
-
34
- # Returns a string representation of the polygon of the form
35
- # points[0] points[1] points[2] ...
36
- # where each point is formatted with Point#to_s
37
- def to_s
38
- @points.join( ' ' )
39
- end
40
-
41
- # @return [String]
42
- def inspect
43
- "(#{ @points.map{|point| point.inspect}.join(', ')})"
44
- end
45
-
46
- # @return [REXML::Element]
47
- def to_xml_element
48
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
49
- xml_element.add_text( self.to_s )
50
- xml_element
51
- end
52
-
53
- # @return [String]
54
- def to_xml
55
- self.to_xml_element.to_s
56
- end
57
-
58
- # Two polygons are equivalent if their collection of points is equivalent.
59
- #
60
- # @return [true,false]
61
- def ==( other )
62
- @points == other.points
63
- end
64
-
65
- # @return [Array<Array(Numeric,Numeric)>]
66
- def self.parse_polygon_string( polygon_string )
67
- polygon_string.split( ' ' ).map{ |coordinate_string| coordinate_string.split( ',' ).map{|coordinate| coordinate.to_f }}
68
- end
69
-
70
- # @return [Polygon]
71
- def self.from_xml_element( polygon_xml_element )
72
- if !polygon_xml_element.text.nil? && !polygon_xml_element.text.empty?
73
- coordinates = self.parse_polygon_string( polygon_xml_element.text )
74
- points = coordinates.map{ |lattitude, longitude| Point.new( :lattitude => lattitude, :longitude => longitude )}
75
- polygon = self.new( :points => points )
76
- else
77
- self.new
78
- end
79
- end
80
-
81
-
82
- # @return [String]
83
- def to_yaml( options = {} )
84
- @points.map{ |point| [ point.lattitude, point.longitude ]}.to_yaml( options )
85
- end
86
-
87
- # @return [Polygon]
88
- def self.from_yaml_data( polygon_yaml_data )
89
- self.new( :points => Array( polygon_yaml_data ).map{ |lattitude, longitude| Point.new( :lattitude => lattitude, :longitude => longitude )})
90
- end
91
-
92
- POINTS_KEY = 'points'
93
-
94
- # @return [Hash]
95
- def to_h
96
- { POINTS_KEY => @points.map{ |point| point.to_h }}
97
- end
7
+ class Polygon < RCAP::Base::Polygon
98
8
 
99
- # @return [Polygon]
100
- def self.from_h( polygon_hash )
101
- self.new( :points => polygon_hash[ POINTS_KEY ].map{ |point_hash| Point.from_h( point_hash )})
9
+ # @return [Class]
10
+ def point_class
11
+ Point
102
12
  end
103
13
  end
104
14
  end
@@ -3,58 +3,17 @@ module RCAP
3
3
 
4
4
  # A Resource object is valid if
5
5
  # * it has a resource description
6
- class Resource
7
- include Validation
6
+ class Resource < RCAP::Base::Resource
8
7
 
9
- # @return [String] Resource Description
10
- attr_accessor( :resource_desc )
11
- # @return [String]
12
- attr_accessor( :mime_type )
13
- # @return [Integer] Expressed in bytes
14
- attr_accessor( :size )
15
- # @return [String] Resource location
16
- attr_accessor( :uri )
17
- # @return [String] Dereferenced URI - contents of URI Base64 encoded
8
+ # @return [String] Dereferenced URI - contents of URI Base64 encoded
18
9
  attr_accessor( :deref_uri )
19
- # @return [String] SHA-1 hash of contents of resource
20
- attr_accessor( :digest )
21
-
22
- validates_presence_of( :resource_desc )
23
10
 
24
- XML_ELEMENT_NAME = 'resource'
25
- MIME_TYPE_ELEMENT_NAME = 'mimeType'
26
- SIZE_ELEMENT_NAME = 'size'
27
- URI_ELEMENT_NAME = 'uri'
28
- DEREF_URI_ELEMENT_NAME = 'derefUri'
29
- DIGEST_ELEMENT_NAME = 'digest'
30
- RESOURCE_DESC_ELEMENT_NAME = 'resourceDesc'
31
-
32
- XPATH = "cap:#{ XML_ELEMENT_NAME }"
33
- MIME_TYPE_XPATH = "cap:#{ MIME_TYPE_ELEMENT_NAME }"
34
- SIZE_XPATH = "cap:#{ SIZE_ELEMENT_NAME }"
35
- URI_XPATH = "cap:#{ URI_ELEMENT_NAME }"
36
- DEREF_URI_XPATH = "cap:#{ DEREF_URI_ELEMENT_NAME }"
37
- DIGEST_XPATH = "cap:#{ DIGEST_ELEMENT_NAME }"
38
- RESOURCE_DESC_XPATH = "cap:#{ RESOURCE_DESC_ELEMENT_NAME }"
39
-
40
- # @param [Hash{Symbol => Object}] attributes
41
- # @option attributes [String] :mime_type
42
- # @option attributes [Numeric] :size Size in bytes
43
- # @option attributes [String] :uri
44
- # @option attributes [String] :deref_uri
45
- # @option attributes [String] :digest
46
- # @option attributes [String] :resource_desc
47
- def initialize( attributes = {} )
48
- @mime_type = attributes[ :mime_type ]
49
- @size = attributes[ :size ]
50
- @uri = attributes[ :uri ]
51
- @deref_uri = attributes[ :deref_uri ]
52
- @digest = attributes[ :digest ]
53
- @resource_desc = attributes[ :resource_desc ]
54
- end
11
+ DEREF_URI_ELEMENT_NAME = 'derefUri'
12
+ DEREF_URI_XPATH = "cap:#{ DEREF_URI_ELEMENT_NAME }"
55
13
 
56
14
  # @return [REXML::Element]
57
- def to_xml_element
15
+ def to_xml_element
16
+ xml_element = super
58
17
  xml_element = REXML::Element.new( XML_ELEMENT_NAME )
59
18
  xml_element.add_element( RESOURCE_DESC_ELEMENT_NAME ).add_text( @resource_desc )
60
19
  xml_element.add_element( MIME_TYPE_ELEMENT_NAME ).add_text( @mime_type ) if @mime_type
@@ -65,32 +24,6 @@ module RCAP
65
24
  xml_element
66
25
  end
67
26
 
68
- # If size is defined returns the size in kilobytes
69
- # @return [Float]
70
- def size_in_kb
71
- if @size
72
- @size.to_f/1024
73
- end
74
- end
75
-
76
- # @return [String]
77
- def to_xml
78
- self.to_xml_element.to_s
79
- end
80
-
81
- # @return [String]
82
- def inspect
83
- [ @resource_desc, @uri, @mime_type, @size ? format( "%.1fKB", @size_in_kb ) : nil ].compact.join(' - ')
84
- end
85
-
86
- # Returns a string representation of the resource of the form
87
- # resource_desc
88
- #
89
- # @return [String]
90
- def to_s
91
- @resource_desc
92
- end
93
-
94
27
  # Retrieves the content at uri and stores it in deref_uri as Base64 encoded text. It will also
95
28
  # calculate the {#digest} on the encoded data using SHA1 and set the {#size}.
96
29
  #
@@ -107,97 +40,58 @@ module RCAP
107
40
  self.calculate_hash_and_size
108
41
  end
109
42
 
110
- # Calculates the SHA-1 hash and size of the contents of {#deref_uri}.
111
- # Returns an array containing the size (in bytes) and SHA-1 hash if
112
- # {#deref_uri} is present otherwise returns nil.
113
- #
114
- # @return [nil,Array(Integer,String)]
115
- def calculate_hash_and_size
116
- if @deref_uri
117
- @digest = Digest::SHA1.hexdigest( @deref_uri )
118
- @size = @deref_uri.bytesize
119
- [ @size, @digest ]
120
- end
121
- end
122
-
123
- # The decoded contents of {#deref_uri} if present otherwise nil.
124
- #
125
- # @return [nil,String]
126
- def decoded_deref_uri
127
- Base64.decode64( @deref_uri ) if @deref_uri
43
+ # @return [String]
44
+ def xmlns
45
+ Alert::XMLNS
128
46
  end
129
47
 
130
48
  # @param [REXML::Element] resource_xml_element
131
49
  # @return [Resource]
132
- def self.from_xml_element( resource_xml_element )
133
- resource = self.new( :resource_desc => RCAP.xpath_text( resource_xml_element, RESOURCE_DESC_XPATH, Alert::XMLNS ),
134
- :uri => RCAP.xpath_text( resource_xml_element, URI_XPATH, Alert::XMLNS ),
135
- :mime_type => RCAP.xpath_text( resource_xml_element, MIME_TYPE_XPATH, Alert::XMLNS ),
136
- :deref_uri => RCAP.xpath_text( resource_xml_element, DEREF_URI_XPATH, Alert::XMLNS ),
137
- :size => RCAP.xpath_text( resource_xml_element, SIZE_XPATH, Alert::XMLNS ).to_i,
138
- :digest => RCAP.xpath_text( resource_xml_element, DIGEST_XPATH, Alert::XMLNS ))
50
+ def self.from_xml_element( resource_xml_element )
51
+ super.tap do |resource|
52
+ resource.deref_uri = RCAP.xpath_text( resource_xml_element, DEREF_URI_XPATH, resource.xmlns )
53
+ end
139
54
  end
140
55
 
141
- RESOURCE_DESC_YAML = "Resource Description"
142
- URI_YAML = "URI"
143
- MIME_TYPE_YAML = "Mime Type"
144
- DEREF_URI_YAML = "Derefrenced URI Data"
145
- SIZE_YAML = "Size"
146
- DIGEST_YAML = "Digest"
56
+ DEREF_URI_YAML = "Derefrenced URI Data"
147
57
 
148
58
  # @param [Hash] options
149
59
  # @return [String]
150
- def to_yaml( options = {} )
151
- RCAP.attribute_values_to_hash(
152
- [ RESOURCE_DESC_YAML, @resource_desc ],
153
- [ URI_YAML, @uri ],
154
- [ MIME_TYPE_YAML, @mime_type ],
155
- [ DEREF_URI_YAML, @deref_uri ],
156
- [ SIZE_YAML, @size ],
157
- [ DIGEST_YAML, @digest ]).to_yaml( options )
60
+ def to_yaml( options = {} )
61
+ RCAP.attribute_values_to_hash( [ RESOURCE_DESC_YAML, @resource_desc ],
62
+ [ URI_YAML, @uri ],
63
+ [ MIME_TYPE_YAML, @mime_type ],
64
+ [ DEREF_URI_YAML, @deref_uri ],
65
+ [ SIZE_YAML, @size ],
66
+ [ DIGEST_YAML, @digest ]).to_yaml( options )
158
67
  end
159
68
 
160
69
  # @param [Hash] resource_yaml_data
161
70
  # @return [Resource]
162
- def self.from_yaml_data( resource_yaml_data )
163
- self.new(
164
- :resource_desc => reource_yaml_data[ RESOURCE_DESC_YAML ],
165
- :uri => reource_yaml_data[ URI_YAML ],
166
- :mime_type => reource_yaml_data[ MIME_TYPE_YAML ],
167
- :deref_uri => reource_yaml_data[ DEREF_URI_YAML ],
168
- :size => reource_yaml_data[ SIZE_YAML ],
169
- :digest => reource_yaml_data[ DIGEST_YAML ]
170
- )
71
+ def self.from_yaml_data( resource_yaml_data )
72
+ super.tap do |resource|
73
+ resource.deref_uri = resource_yaml_data[ DEREF_URI_YAML ]
74
+ end
171
75
  end
172
76
 
173
- RESOURCE_DESC_KEY = 'resource_desc'
174
- URI_KEY = 'uri'
175
- MIME_TYPE_KEY = 'mime_type'
176
- DEREF_URI_KEY = 'deref_uri'
177
- SIZE_KEY = 'size'
178
- DIGEST_KEY = 'digest'
77
+ DEREF_URI_KEY = 'deref_uri'
179
78
 
180
79
  # @return [Hash]
181
- def to_h
182
- RCAP.attribute_values_to_hash(
183
- [ RESOURCE_DESC_KEY, @resource_desc ],
184
- [ URI_KEY, @uri],
185
- [ MIME_TYPE_KEY, @mime_type],
186
- [ DEREF_URI_KEY, @deref_uri],
187
- [ SIZE_KEY, @size ],
188
- [ DIGEST_KEY, @digest ])
80
+ def to_h
81
+ RCAP.attribute_values_to_hash( [ RESOURCE_DESC_KEY, @resource_desc ],
82
+ [ URI_KEY, @uri],
83
+ [ MIME_TYPE_KEY, @mime_type],
84
+ [ DEREF_URI_KEY, @deref_uri],
85
+ [ SIZE_KEY, @size ],
86
+ [ DIGEST_KEY, @digest ])
189
87
  end
190
88
 
191
89
  # @param [Hash] resource_hash
192
90
  # @return [Resource]
193
- def self.from_h( resource_hash )
194
- self.new(
195
- :resource_desc => resource_hash[ RESOURCE_DESC_KEY ],
196
- :uri => resource_hash[ URI_KEY ],
197
- :mime_type => resource_hash[ MIME_TYPE_KEY ],
198
- :deref_uri => resource_hash[ DEREF_URI_KEY ],
199
- :size => resource_hash[ SIZE_KEY ],
200
- :digest => resource_hash[ DIGEST_KEY ])
91
+ def self.from_h( resource_hash )
92
+ super.tap do |resource|
93
+ resource.deref_uri = resource_hash[ DEREF_URI_KEY ]
94
+ end
201
95
  end
202
96
  end
203
97
  end