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
@@ -1,30 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_2
|
3
|
-
|
4
5
|
# A Resource object is valid if
|
5
6
|
# * it has a resource description
|
6
7
|
# * it has a mime_type
|
7
8
|
class Resource < RCAP::Base::Resource
|
8
|
-
|
9
9
|
# @return [String] Dereferenced URI - contents of URI Base64 encoded
|
10
|
-
attr_accessor(
|
10
|
+
attr_accessor(:deref_uri)
|
11
11
|
|
12
|
-
validates_presence_of(
|
12
|
+
validates_presence_of(:mime_type)
|
13
13
|
|
14
|
-
DEREF_URI_ELEMENT_NAME
|
14
|
+
DEREF_URI_ELEMENT_NAME = 'derefUri'
|
15
15
|
|
16
|
-
DEREF_URI_XPATH
|
16
|
+
DEREF_URI_XPATH = "cap:#{DEREF_URI_ELEMENT_NAME}"
|
17
17
|
|
18
18
|
# @return [REXML::Element]
|
19
19
|
def to_xml_element
|
20
|
-
xml_element =
|
21
|
-
xml_element
|
22
|
-
xml_element.add_element(
|
23
|
-
xml_element.add_element(
|
24
|
-
xml_element.add_element(
|
25
|
-
xml_element.add_element(
|
26
|
-
xml_element.add_element(
|
27
|
-
xml_element.add_element( DIGEST_ELEMENT_NAME ).add_text( @digest ) if @digest
|
20
|
+
xml_element = REXML::Element.new(XML_ELEMENT_NAME)
|
21
|
+
xml_element.add_element(RESOURCE_DESC_ELEMENT_NAME).add_text(@resource_desc)
|
22
|
+
xml_element.add_element(MIME_TYPE_ELEMENT_NAME).add_text(@mime_type) if @mime_type
|
23
|
+
xml_element.add_element(SIZE_ELEMENT_NAME).add_text(@size.to_s) if @size
|
24
|
+
xml_element.add_element(URI_ELEMENT_NAME).add_text(@uri) if @uri
|
25
|
+
xml_element.add_element(DEREF_URI_ELEMENT_NAME).add_text(@deref_uri) if @deref_uri
|
26
|
+
xml_element.add_element(DIGEST_ELEMENT_NAME).add_text(@digest) if @digest
|
28
27
|
xml_element
|
29
28
|
end
|
30
29
|
|
@@ -39,9 +38,9 @@ module RCAP
|
|
39
38
|
#
|
40
39
|
# @return [Array(Integer,String)]
|
41
40
|
def dereference_uri!
|
42
|
-
content = URI.parse(
|
43
|
-
@deref_uri = Base64.encode64(
|
44
|
-
|
41
|
+
content = URI.parse(uri).read
|
42
|
+
@deref_uri = Base64.encode64(content)
|
43
|
+
calculate_hash_and_size
|
45
44
|
end
|
46
45
|
|
47
46
|
# @return [String]
|
@@ -51,51 +50,52 @@ module RCAP
|
|
51
50
|
|
52
51
|
# @param [REXML::Element] resource_xml_element
|
53
52
|
# @return [Resource]
|
54
|
-
def self.from_xml_element(
|
53
|
+
def self.from_xml_element(resource_xml_element)
|
55
54
|
super.tap do |resource|
|
56
|
-
resource.deref_uri = RCAP.xpath_text(
|
55
|
+
resource.deref_uri = RCAP.xpath_text(resource_xml_element, DEREF_URI_XPATH, resource.xmlns)
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
DEREF_URI_YAML
|
59
|
+
DEREF_URI_YAML = 'Derefrenced URI Data'
|
61
60
|
|
62
61
|
# @param [Hash] options
|
63
62
|
# @return [String]
|
64
|
-
def to_yaml(
|
63
|
+
def to_yaml(options = {})
|
65
64
|
RCAP.attribute_values_to_hash(
|
66
|
-
[
|
67
|
-
[
|
68
|
-
[
|
69
|
-
[
|
70
|
-
[
|
71
|
-
[
|
65
|
+
[RESOURCE_DESC_YAML, @resource_desc],
|
66
|
+
[URI_YAML, @uri],
|
67
|
+
[MIME_TYPE_YAML, @mime_type],
|
68
|
+
[DEREF_URI_YAML, @deref_uri],
|
69
|
+
[SIZE_YAML, @size],
|
70
|
+
[DIGEST_YAML, @digest]
|
71
|
+
).to_yaml(options)
|
72
72
|
end
|
73
73
|
|
74
74
|
# @param [Hash] resource_yaml_data
|
75
75
|
# @return [Resource]
|
76
|
-
def self.from_yaml_data(
|
76
|
+
def self.from_yaml_data(resource_yaml_data)
|
77
77
|
super.tap do |resource|
|
78
|
-
resource.deref_uri = resource_yaml_data[
|
78
|
+
resource.deref_uri = resource_yaml_data[DEREF_URI_YAML].strip if resource_yaml_data[DEREF_URI_YAML]
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
DEREF_URI_KEY
|
82
|
+
DEREF_URI_KEY = 'deref_uri'
|
83
83
|
|
84
84
|
# @return [Hash]
|
85
85
|
def to_h
|
86
|
-
RCAP.attribute_values_to_hash(
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
RCAP.attribute_values_to_hash([RESOURCE_DESC_KEY, @resource_desc],
|
87
|
+
[URI_KEY, @uri],
|
88
|
+
[MIME_TYPE_KEY, @mime_type],
|
89
|
+
[DEREF_URI_KEY, @deref_uri],
|
90
|
+
[SIZE_KEY, @size],
|
91
|
+
[DIGEST_KEY, @digest])
|
92
92
|
end
|
93
93
|
|
94
94
|
# @param [Hash] resource_hash
|
95
95
|
# @return [Resource]
|
96
|
-
def self.from_h(
|
96
|
+
def self.from_h(resource_hash)
|
97
97
|
super.tap do |resource|
|
98
|
-
resource.deref_uri = resource_hash[
|
98
|
+
resource.deref_uri = resource_hash[DEREF_URI_KEY].strip if resource_hash[DEREF_URI_KEY]
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/lib/rcap/config.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
|
-
XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new(
|
4
|
+
XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new(2)
|
3
5
|
XML_PRETTY_PRINTER.compact = true
|
4
6
|
|
5
|
-
RCAP_TIME_FORMAT =
|
6
|
-
RCAP_ZONE_FORMAT =
|
7
|
+
RCAP_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
|
8
|
+
RCAP_ZONE_FORMAT = '%+03i:00'
|
7
9
|
end
|
@@ -1,20 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validation
|
2
4
|
module ClassMethods
|
3
|
-
|
4
|
-
|
5
|
-
CAP_INTEGER_REGEX = Regexp.new( '\-{0,1}A[+-]?\d+\Z' )
|
5
|
+
CAP_NUMBER_REGEX = Regexp.new('^-{0,1}\d*\.{0,1}\d+$')
|
6
|
+
CAP_INTEGER_REGEX = Regexp.new('\-{0,1}A[+-]?\d+\Z')
|
6
7
|
|
7
8
|
# @example
|
8
9
|
# validates_inclusion_of( :status, :in => VALID_STATUSES )
|
9
|
-
def validates_inclusion_of(
|
10
|
+
def validates_inclusion_of(*attributes)
|
10
11
|
options = {
|
11
|
-
:
|
12
|
-
}.merge!(
|
12
|
+
message: 'is not in the required range'
|
13
|
+
}.merge!(attributes.extract_options!)
|
13
14
|
|
14
|
-
validates_each(
|
15
|
-
next if
|
16
|
-
unless options[
|
17
|
-
object.errors[
|
15
|
+
validates_each(*attributes) do |object, attribute, value|
|
16
|
+
next if value.nil? && options[:allow_nil]
|
17
|
+
unless options[:in].include?(value)
|
18
|
+
object.errors[attribute] << options[:message]
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -22,134 +23,130 @@ module Validation
|
|
22
23
|
# Will validate all members of a collection are found in a given collection.
|
23
24
|
# @example
|
24
25
|
# validates_inclusion_of_members_of( :categories, :in => VALID_CATEGORIES )
|
25
|
-
def validates_inclusion_of_members_of(
|
26
|
+
def validates_inclusion_of_members_of(*attributes)
|
26
27
|
options = {
|
27
|
-
:
|
28
|
-
}.merge!(
|
28
|
+
message: 'contains members that are not valid'
|
29
|
+
}.merge!(attributes.extract_options!)
|
29
30
|
|
30
|
-
validates_each(
|
31
|
-
next if (
|
32
|
-
unless collection.all?{ |member| options[
|
33
|
-
object.errors[
|
31
|
+
validates_each(*attributes) do |object, attribute, collection|
|
32
|
+
next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
|
33
|
+
unless collection.all? { |member| options[:in].include?(member) }
|
34
|
+
object.errors[attribute] << options[:message]
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
def validates_length_of_members_of(
|
39
|
+
def validates_length_of_members_of(*attributes)
|
39
40
|
options = {
|
40
|
-
:
|
41
|
-
}.merge!(
|
41
|
+
message: 'contains members with incorrect length'
|
42
|
+
}.merge!(attributes.extract_options!)
|
42
43
|
|
43
|
-
validates_each(
|
44
|
-
next if (
|
45
|
-
unless options[
|
46
|
-
object.errors[
|
44
|
+
validates_each(*attributes) do |object, attribute, collection|
|
45
|
+
next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
|
46
|
+
unless options[:minimum] && collection.length >= options[:minimum]
|
47
|
+
object.errors[attribute] << options[:message]
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def validates_validity_of(
|
52
|
+
def validates_validity_of(*attributes)
|
52
53
|
options = {
|
53
|
-
:
|
54
|
-
}.merge!(
|
54
|
+
message: 'is not valid'
|
55
|
+
}.merge!(attributes.extract_options!)
|
55
56
|
|
56
|
-
validates_each(
|
57
|
-
next if
|
58
|
-
|
59
|
-
object.errors[ attribute ] << options[ :message ]
|
60
|
-
end
|
57
|
+
validates_each(*attributes) do |object, attribute, value|
|
58
|
+
next if value.nil? && options[:allow_nil]
|
59
|
+
object.errors[attribute] << options[:message] unless value&.valid?
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
64
|
-
def validates_collection_of(
|
63
|
+
def validates_collection_of(*attributes)
|
65
64
|
options = {
|
66
|
-
:
|
67
|
-
}.merge!(
|
65
|
+
message: 'contains an invalid element'
|
66
|
+
}.merge!(attributes.extract_options!)
|
68
67
|
|
69
|
-
validates_each(
|
70
|
-
next if (
|
71
|
-
unless collection.all?
|
72
|
-
object.errors[
|
68
|
+
validates_each(*attributes) do |object, attribute, collection|
|
69
|
+
next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
|
70
|
+
unless collection.all?(&:valid?)
|
71
|
+
object.errors[attribute] << options[:message]
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
|
-
def validates_dependency_of(
|
76
|
+
def validates_dependency_of(*attributes)
|
78
77
|
options = {
|
79
|
-
:
|
80
|
-
}.merge!(
|
78
|
+
message: 'is dependent on :attribute being defined'
|
79
|
+
}.merge!(attributes.extract_options!)
|
81
80
|
|
82
|
-
validates_each(
|
81
|
+
validates_each(*attributes) do |object, attribute, value|
|
83
82
|
next if value.blank?
|
84
|
-
contingent_on_attribute = object.send(
|
85
|
-
contingent_on_attribute_value = options[
|
83
|
+
contingent_on_attribute = object.send(options[:on])
|
84
|
+
contingent_on_attribute_value = options[:with_value]
|
86
85
|
|
87
86
|
if contingent_on_attribute.nil? || !contingent_on_attribute_value.nil? && contingent_on_attribute_value != contingent_on_attribute
|
88
|
-
object.errors[
|
87
|
+
object.errors[attribute] << options[:message].gsub(/:attribute/, options[:on].to_s)
|
89
88
|
end
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
def validates_conditional_presence_of(
|
92
|
+
def validates_conditional_presence_of(*attributes)
|
94
93
|
options = {
|
95
|
-
:
|
96
|
-
}.merge!(
|
94
|
+
message: 'is not defined but is required by :contingent_attribute'
|
95
|
+
}.merge!(attributes.extract_options!)
|
97
96
|
|
98
|
-
validates_each(
|
99
|
-
contingent_attribute_value = object.send(
|
100
|
-
required_contingent_attribute_value = options[
|
97
|
+
validates_each(*attributes) do |object, attribute, value|
|
98
|
+
contingent_attribute_value = object.send(options[:when])
|
99
|
+
required_contingent_attribute_value = options[:is]
|
101
100
|
|
102
|
-
next if contingent_attribute_value.nil? || contingent_attribute_value != required_contingent_attribute_value && !options[
|
101
|
+
next if contingent_attribute_value.nil? || contingent_attribute_value != required_contingent_attribute_value && !options[:is].blank?
|
103
102
|
if value.blank?
|
104
|
-
object.errors[
|
103
|
+
object.errors[attribute] << options[:message].gsub(/:contingent_attribute/, options[:whenn].to_s)
|
105
104
|
end
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
|
-
|
110
|
-
def validates_numericality_of( *attributes )
|
108
|
+
def validates_numericality_of(*attributes)
|
111
109
|
options = {
|
112
|
-
:
|
110
|
+
message: 'is not a number or does not meet a conditional requirement'
|
113
111
|
}.merge!(attributes.extract_options!)
|
114
112
|
|
115
113
|
re = options[:only_integer] ? CAP_INTEGER_REGEX : CAP_NUMBER_REGEX
|
116
114
|
|
117
|
-
validates_each(
|
118
|
-
next if
|
119
|
-
unless (
|
120
|
-
|
121
|
-
|
122
|
-
object.errors[
|
115
|
+
validates_each(*attributes) do |object, attribute, value|
|
116
|
+
next if value.nil? && options[:allow_nil]
|
117
|
+
unless (value.to_s =~ re) &&
|
118
|
+
(options[:greater_than].nil? || value && value > options[:greater_than]) &&
|
119
|
+
(options[:greater_than_or_equal].nil? || value && value >= options[:greater_than_or_equal])
|
120
|
+
object.errors[attribute] << options[:message]
|
123
121
|
end
|
124
122
|
end
|
125
123
|
end
|
126
124
|
|
127
|
-
|
128
|
-
def validates_responsiveness_of( *attributes )
|
125
|
+
def validates_responsiveness_of(*attributes)
|
129
126
|
options = {
|
130
|
-
:
|
131
|
-
}.merge!(
|
127
|
+
message: 'does not respond to the given method'
|
128
|
+
}.merge!(attributes.extract_options!)
|
132
129
|
|
133
|
-
validates_each(
|
134
|
-
next if
|
135
|
-
unless options[
|
136
|
-
object.errors[
|
130
|
+
validates_each(*attributes) do |object, attribute, _value|
|
131
|
+
next if collection.nil? && options[:allow_nil]
|
132
|
+
unless options[:to].all? { |method_name| object.respond_to?(method_name) }
|
133
|
+
object.errors[attribute] << options [:message]
|
137
134
|
end
|
138
135
|
end
|
139
136
|
end
|
140
137
|
|
141
|
-
def validates_equality_of_first_and_last(
|
138
|
+
def validates_equality_of_first_and_last(*attributes)
|
142
139
|
options = {
|
143
|
-
:
|
144
|
-
}.merge!(
|
140
|
+
message: 'does not have equal first and last elements'
|
141
|
+
}.merge!(attributes.extract_options!)
|
145
142
|
|
146
|
-
validates_each(
|
147
|
-
next if
|
143
|
+
validates_each(*attributes) do |object, attribute, collection|
|
144
|
+
next if collection.nil? && options[:allow_nil]
|
145
|
+
next if collection.empty? && options[:allow_empty]
|
148
146
|
unless collection.first == collection.last
|
149
|
-
object.errors[
|
147
|
+
object.errors[attribute] << options[:message]
|
150
148
|
end
|
151
149
|
end
|
152
150
|
end
|
153
151
|
end
|
154
152
|
end
|
155
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Array
|
2
4
|
# Formats an array into a string suitable for a CAP message.
|
3
5
|
#
|
@@ -6,7 +8,7 @@ class Array
|
|
6
8
|
# [ "one", "two words", "three" ].to_s_for_cap # => "one \"two words\" three"
|
7
9
|
# @see String#unpack_cap_list
|
8
10
|
def to_s_for_cap
|
9
|
-
|
11
|
+
map { |element| element.to_s.for_cap_list }.join(' ')
|
10
12
|
end
|
11
13
|
|
12
14
|
def blank?
|
data/lib/rcap/extensions/date.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Date
|
2
4
|
alias inspect to_s
|
3
5
|
|
@@ -6,6 +8,6 @@ class Date
|
|
6
8
|
# @example
|
7
9
|
# Date.today.to_s_for_cap # => "2011-10-26T00:00:00+00:00"
|
8
10
|
def to_s_for_cap
|
9
|
-
|
11
|
+
to_datetime.to_s_for_cap
|
10
12
|
end
|
11
13
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class DateTime
|
2
4
|
alias inspect to_s
|
3
5
|
|
@@ -6,7 +8,7 @@ class DateTime
|
|
6
8
|
# @example
|
7
9
|
# DateTime.now.to_s_for_cap # => "2011-10-26T21:45:00+02:00"
|
8
10
|
def to_s_for_cap
|
9
|
-
t =
|
11
|
+
t = strftime(RCAP::RCAP_TIME_FORMAT) + format(RCAP::RCAP_ZONE_FORMAT, utc_hours_offset)
|
10
12
|
t.sub(/\+(00:\d\d)$/, '-\1')
|
11
13
|
end
|
12
14
|
|
@@ -15,7 +17,8 @@ class DateTime
|
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
20
|
+
|
18
21
|
def utc_hours_offset
|
19
|
-
|
22
|
+
offset * 24
|
20
23
|
end
|
21
24
|
end
|