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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a0436dc9e0622316c63a9a049ebe243ebe50bd0
4
- data.tar.gz: f598315aff5dea761320ef51fe2f64709bba9073
3
+ metadata.gz: 76da3fa471566c2c7f1e99fe5d830f66288924df
4
+ data.tar.gz: d55dfa69f9959a7d2bc53ece11d6d82c5b69dc10
5
5
  SHA512:
6
- metadata.gz: c19ae66a76c4abcd5a4c431e567a0cf55060e35827afba22c2ba27bc35d9f7d1773c009e55b9e3a48d61221aca7c3811ec2a9907f6517432d7df7eebdcbd21ed
7
- data.tar.gz: 2c17f6398cd89b909e36e8d3dd6d42a5f761ae7df2da319cf5ca99b609eb17a6c9e82dab5496cc13a5521dfc0e745a0ea2365589494ece87820fa919a7eed6d3
6
+ metadata.gz: ee814d1eeed9ea6892795afea4075fbe9a7c833d033447ccb292b02e18e46354202082f5cb11690872a172d91a5fd7198c6aed517a9582e5ca768b00fb2d9aac
7
+ data.tar.gz: de04ea1ad3da58c3e2f1baf56e9d619191a4d59605e2cd30dd030e41c49ff65ea74ba3c8b369c690746e000103e4e0b20713e8944d3182066bbfb75fb9e19a50
@@ -0,0 +1,3 @@
1
+ ## 0.3.3 - Oct 2, 2018
2
+
3
+ - Optimized setting attributes
@@ -1,3 +1,3 @@
1
1
  module OpenXmlPackage
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -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
- bad_names = %w{ tag name namespace properties_tag }
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
- message = "Required attribute(s) #{unset_attributes.join(", ")} have not been set"
90
- raise OpenXml::UnmetRequirementError, message if unset_attributes.any?
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
- message = "Invalid #{name}: frame must be true or false"
95
- raise ArgumentError, message unless [true, false].member? value
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
- message = "Invalid #{name}: must be :auto or a hex color, e.g. 4F1B8C"
100
- raise ArgumentError, message unless value == :auto || value =~ /^[0-9A-F]{6}$/
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
- message = "Invalid #{name}: must be a two-digit hex number, e.g. BF"
105
- raise ArgumentError, message unless value =~ /^[0-9A-F]{2}$/
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
- message = "Invalid #{name}: must be a four-digit hex number, e.g. BF12"
110
- raise ArgumentError, message unless value =~ /^[0-9A-F]{4}$/
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
- message = "Invalid #{name}: must be an eight-digit hex number, e.g., FFAC0013"
115
- raise ArgumentError, message unless value =~ /^[0-9A-F]{8}$/
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
- message = "Invalid #{name}: must be a string of hexadecimal numbers, e.g. FFA23C6E"
120
- raise ArgumentError, message unless value =~ /^[0-9A-F]+$/
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
- message = "Invalid #{name}: must be an integer"
125
- raise ArgumentError, message unless value.is_a?(Integer)
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
- message = "Invalid #{name}: must be a positive integer"
130
- raise ArgumentError, message unless value.is_a?(Integer) && value >= 0
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
- message = "Invalid #{name}: must be a string"
135
- raise ArgumentError, message if !value.is_a?(String) || value.length.zero?
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
- message = "Invalid #{name}: must be a string, even if the string is empty"
140
- raise ArgumentError, message unless value.is_a?(String)
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
- message = "Invalid #{name}: must be a number between #{range.begin} and #{range.end}"
145
- raise ArgumentError, message unless range.include?(value.to_i)
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
- message = "Invalid #{name}: must be a percentage"
150
- raise ArgumentError, message unless value.is_a?(String) && value =~ /-?[0-9]+(\.[0-9]+)?%/ # Regex supplied in sec. 22.9.2.9 of Office Open XML docs
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
- message = "Invalid #{name}: must be one of #{list} (was #{value.inspect})"
159
- raise ArgumentError, message unless list.member?(value)
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
- message = "Value does not match #{regexp}"
164
- raise ArgumentError, message unless value =~ regexp
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
- define_method "#{name}=" do |value|
99
- properties_element.public_send :"#{name}=", value
100
- end
98
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
99
+ def #{name}=(value)
100
+ properties_element.#{name} = value
101
+ end
101
102
 
102
- define_method name.to_s do
103
- properties_element.public_send name.to_sym
104
- end
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
- unique = other_names.none? { |other_name| instance_variable_defined?("@#{other_name}") }
203
- message = "Property #{name} cannot also be set with #{other_names.join(", ")}."
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
- message = "Required choice from among group(s) (#{unmet_choice_groups.join("), (")}) not made"
218
- raise OpenXml::UnmetRequirementError, message if unmet_choice_groups.any?
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
- message = "Invalid tag name for #{name}: #{tag.inspect}. It should be one of #{allowed}."
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?
@@ -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.1"
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.2
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: 2017-09-26 00:00:00.000000000 Z
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.1
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.1
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