rcap 2.4.1 → 2.5.0

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