openxml-package 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/openxml-package/version.rb +1 -1
- data/lib/openxml/has_attributes.rb +34 -32
- data/lib/openxml/has_properties.rb +12 -11
- data/lib/openxml/properties/base_property.rb +1 -2
- data/openxml-package.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76da3fa471566c2c7f1e99fe5d830f66288924df
|
4
|
+
data.tar.gz: d55dfa69f9959a7d2bc53ece11d6d82c5b69dc10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee814d1eeed9ea6892795afea4075fbe9a7c833d033447ccb292b02e18e46354202082f5cb11690872a172d91a5fd7198c6aed517a9582e5ca768b00fb2d9aac
|
7
|
+
data.tar.gz: de04ea1ad3da58c3e2f1baf56e9d619191a4d59605e2cd30dd030e41c49ff65ea74ba3c8b369c690746e000103e4e0b20713e8944d3182066bbfb75fb9e19a50
|
data/CHANGELOG.md
ADDED
@@ -9,9 +9,10 @@ module OpenXml
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
|
12
|
+
RESERVED_NAMES = %w{ tag name namespace properties_tag }.freeze
|
13
|
+
|
12
14
|
def attribute(name, expects: nil, one_of: nil, in_range: nil, displays_as: nil, namespace: nil, matches: nil, validation: nil, required: false, deprecated: false)
|
13
|
-
|
14
|
-
raise ArgumentError if bad_names.member? name.to_s
|
15
|
+
raise ArgumentError if RESERVED_NAMES.member? name.to_s
|
15
16
|
|
16
17
|
required_attributes.push(name) if required
|
17
18
|
|
@@ -86,68 +87,69 @@ module OpenXml
|
|
86
87
|
unset_attributes = required_attributes.reject do |attr|
|
87
88
|
instance_variable_defined?("@#{attr}")
|
88
89
|
end
|
89
|
-
|
90
|
-
|
90
|
+
return if unset_attributes.empty?
|
91
|
+
|
92
|
+
raise OpenXml::UnmetRequirementError, "Required attribute(s) #{unset_attributes.join(", ")} have not been set"
|
91
93
|
end
|
92
94
|
|
93
95
|
def boolean(value)
|
94
|
-
|
95
|
-
raise ArgumentError,
|
96
|
+
return if [true, false].member? value
|
97
|
+
raise ArgumentError, "Invalid #{name}: frame must be true or false"
|
96
98
|
end
|
97
99
|
|
98
100
|
def hex_color(value)
|
99
|
-
|
100
|
-
raise ArgumentError,
|
101
|
+
return if value == :auto || value =~ /^[0-9A-F]{6}$/
|
102
|
+
raise ArgumentError, "Invalid #{name}: must be :auto or a hex color, e.g. 4F1B8C"
|
101
103
|
end
|
102
104
|
|
103
105
|
def hex_digit(value)
|
104
|
-
|
105
|
-
raise ArgumentError,
|
106
|
+
return if value =~ /^[0-9A-F]{2}$/
|
107
|
+
raise ArgumentError, "Invalid #{name}: must be a two-digit hex number, e.g. BF"
|
106
108
|
end
|
107
109
|
|
108
110
|
def hex_digit_4(value)
|
109
|
-
|
110
|
-
raise ArgumentError,
|
111
|
+
return if value =~ /^[0-9A-F]{4}$/
|
112
|
+
raise ArgumentError, "Invalid #{name}: must be a four-digit hex number, e.g. BF12"
|
111
113
|
end
|
112
114
|
|
113
115
|
def long_hex_number(value)
|
114
|
-
|
115
|
-
raise ArgumentError,
|
116
|
+
return if value =~ /^[0-9A-F]{8}$/
|
117
|
+
raise ArgumentError, "Invalid #{name}: must be an eight-digit hex number, e.g., FFAC0013"
|
116
118
|
end
|
117
119
|
|
118
120
|
def hex_string(value)
|
119
|
-
|
120
|
-
raise ArgumentError,
|
121
|
+
return if value =~ /^[0-9A-F]+$/
|
122
|
+
raise ArgumentError, "Invalid #{name}: must be a string of hexadecimal numbers, e.g. FFA23C6E"
|
121
123
|
end
|
122
124
|
|
123
125
|
def integer(value)
|
124
|
-
|
125
|
-
raise ArgumentError,
|
126
|
+
return if value.is_a?(Integer)
|
127
|
+
raise ArgumentError, "Invalid #{name}: must be an integer"
|
126
128
|
end
|
127
129
|
|
128
130
|
def positive_integer(value)
|
129
|
-
|
130
|
-
raise ArgumentError,
|
131
|
+
return if value.is_a?(Integer) && value >= 0
|
132
|
+
raise ArgumentError, "Invalid #{name}: must be a positive integer"
|
131
133
|
end
|
132
134
|
|
133
135
|
def string(value)
|
134
|
-
|
135
|
-
raise ArgumentError,
|
136
|
+
return if value.is_a?(String) && value.length > 0
|
137
|
+
raise ArgumentError, "Invalid #{name}: must be a string"
|
136
138
|
end
|
137
139
|
|
138
140
|
def string_or_blank(value)
|
139
|
-
|
140
|
-
raise ArgumentError,
|
141
|
+
return if value.is_a?(String)
|
142
|
+
raise ArgumentError, "Invalid #{name}: must be a string, even if the string is empty"
|
141
143
|
end
|
142
144
|
|
143
145
|
def in_range?(value, range)
|
144
|
-
|
145
|
-
raise ArgumentError,
|
146
|
+
return if range.include?(value.to_i)
|
147
|
+
raise ArgumentError, "Invalid #{name}: must be a number between #{range.begin} and #{range.end}"
|
146
148
|
end
|
147
149
|
|
148
150
|
def percentage(value)
|
149
|
-
|
150
|
-
raise ArgumentError,
|
151
|
+
return if value.is_a?(String) && value =~ /-?[0-9]+(\.[0-9]+)?%/ # Regex supplied in sec. 22.9.2.9 of Office Open XML docs
|
152
|
+
raise ArgumentError, "Invalid #{name}: must be a percentage"
|
151
153
|
end
|
152
154
|
|
153
155
|
def on_or_off(value)
|
@@ -155,13 +157,13 @@ module OpenXml
|
|
155
157
|
end
|
156
158
|
|
157
159
|
def valid_in?(value, list)
|
158
|
-
|
159
|
-
raise ArgumentError,
|
160
|
+
return if list.member?(value)
|
161
|
+
raise ArgumentError, "Invalid #{name}: must be one of #{list} (was #{value.inspect})"
|
160
162
|
end
|
161
163
|
|
162
164
|
def matches?(value, regexp)
|
163
|
-
|
164
|
-
raise ArgumentError,
|
165
|
+
return if value =~ regexp
|
166
|
+
raise ArgumentError, "Value does not match #{regexp}"
|
165
167
|
end
|
166
168
|
|
167
169
|
end
|
@@ -95,13 +95,15 @@ module OpenXml
|
|
95
95
|
|
96
96
|
def properties_attribute(name, **args)
|
97
97
|
properties_element.attribute name, **args
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
99
|
+
def #{name}=(value)
|
100
|
+
properties_element.#{name} = value
|
101
|
+
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
def #{name}
|
104
|
+
properties_element.#{name}
|
105
|
+
end
|
106
|
+
RUBY
|
105
107
|
end
|
106
108
|
|
107
109
|
def properties_element
|
@@ -199,9 +201,8 @@ module OpenXml
|
|
199
201
|
|
200
202
|
def ensure_unique_in_group(name, group_index)
|
201
203
|
other_names = (choice_groups[group_index] - [name])
|
202
|
-
|
203
|
-
|
204
|
-
raise ChoiceGroupUniqueError, message unless unique
|
204
|
+
return if other_names.none? { |other_name| instance_variable_defined?("@#{other_name}") }
|
205
|
+
raise ChoiceGroupUniqueError, "Property #{name} cannot also be set with #{other_names.join(", ")}."
|
205
206
|
end
|
206
207
|
|
207
208
|
def unmet_choices
|
@@ -214,8 +215,8 @@ module OpenXml
|
|
214
215
|
|
215
216
|
def ensure_required_choices
|
216
217
|
unmet_choice_groups = unmet_choices.map { |index| choice_groups[index].join(", ") }
|
217
|
-
|
218
|
-
raise OpenXml::UnmetRequirementError,
|
218
|
+
return if unmet_choice_groups.empty?
|
219
|
+
raise OpenXml::UnmetRequirementError, "Required choice from among group(s) (#{unmet_choice_groups.join("), (")}) not made"
|
219
220
|
end
|
220
221
|
|
221
222
|
end
|
@@ -38,8 +38,7 @@ module OpenXml
|
|
38
38
|
def validate_tag(tag)
|
39
39
|
return if self.class.allowed_tags.include?(tag)
|
40
40
|
allowed = self.class.allowed_tags.join(", ")
|
41
|
-
|
42
|
-
raise ArgumentError, message
|
41
|
+
raise ArgumentError, "Invalid tag name for #{name}: #{tag.inspect}. It should be one of #{allowed}."
|
43
42
|
end
|
44
43
|
|
45
44
|
def render?
|
data/openxml-package.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "rubyzip", "~> 1.2.
|
22
|
+
spec.add_dependency "rubyzip", "~> 1.2.2"
|
23
23
|
spec.add_dependency "nokogiri"
|
24
24
|
spec.add_dependency "ox"
|
25
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openxml-package
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.
|
19
|
+
version: 1.2.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2.
|
26
|
+
version: 1.2.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +187,7 @@ extra_rdoc_files: []
|
|
187
187
|
files:
|
188
188
|
- ".gitignore"
|
189
189
|
- ".travis.yml"
|
190
|
+
- CHANGELOG.md
|
190
191
|
- Gemfile
|
191
192
|
- LICENSE.txt
|
192
193
|
- README.md
|