ooxml_excel 0.0.3.3 → 0.0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ada37077ee27fdaea8c64512a7abf812c0eff03
4
- data.tar.gz: ff04e370268cec5b568cf99b67bc74cc7abedd65
3
+ metadata.gz: 20ed498375c405e27133da180b758ea5380dcd86
4
+ data.tar.gz: 1a15b0d9cac077fe649fe0f23dfb4a4d0e80471f
5
5
  SHA512:
6
- metadata.gz: 29dd6544259f4b24a954842f929d400913964956646f0f05df2b8d554737b15267cc6a1af37f5143723f664554e460d31ae57f4f0abf4f3972b24d085ea4b0d6
7
- data.tar.gz: 20a7af6b3bdb49be90ff77500c35dee10e9746d09e6baf8132679b7a986fbea9023443213121966495f512f7edb72705291d989415f875341033661f9290d7ed
6
+ metadata.gz: a283b2355dd5eb4fab3a6bfec94f0aaf79f74efe4fdf52b01057193883b44ffc5ed35f1e8d802287cd712ecdba096cfafdf23de366167e3c7ca5745ff4f14fb1
7
+ data.tar.gz: d12f8eec8217bb29f52d0af5d23daa787e23c2741146beb003adf9332ca2c39cfb5c2e1b35bb023266d6237394e31b65099a8200666b184695decdc5b5b82a0b
@@ -19,7 +19,7 @@ module OOXML
19
19
  end
20
20
 
21
21
  def data_validation(cell_ref)
22
- data_validations.find { |data_validation| data_validation.sqref_range.include?(cell_ref)}
22
+ data_validations.find { |data_validation| data_validation.in_sqref_range?(cell_ref)}
23
23
  end
24
24
 
25
25
  def column(id)
@@ -260,21 +260,12 @@ module OOXML
260
260
  class DataValidation
261
261
  attr_accessor :allow_blank, :prompt, :type, :sqref, :formula
262
262
 
263
- def sqref_range
264
- @sqref_range ||= begin
265
- # "BH5:BH271 BI5:BI271"
266
- sqref.split( ' ').map do |splitted_by_space_sqref|
267
- # ["BH5:BH271, "BI5:BI271"]
268
- if splitted_by_space_sqref.is_a?(Array)
269
- splitted_by_space_sqref.map do |sqref|
270
- split_sqref(sqref)
271
- end
272
- else
273
- # "BH5:BH271"
274
- split_sqref(splitted_by_space_sqref)
275
- end
276
- end.flatten.uniq
277
- end
263
+ def in_sqref_range?(cell_id)
264
+ return if cell_id.blank?
265
+ cell_letter = cell_id.gsub(/[\d]/, '')
266
+ index = cell_id.gsub(/[^\d]/, '').to_i
267
+ range = sqref_range.find { |cell_letter_range, row_range| cell_letter_range.include?(cell_letter)}
268
+ range.last.include?(index) if range.present?
278
269
  end
279
270
 
280
271
  def self.load_from_node(data_validation_node)
@@ -296,20 +287,34 @@ module OOXML
296
287
  attrs.each { |property, value| send("#{property}=", value)}
297
288
  end
298
289
 
299
- def split_sqref(sqref)
300
- # Example: "BH5:BH271"
301
- # starting_reference: BH5
302
- # ending_reference: BH271
303
- starting_reference, ending_reference = sqref.split(":")
304
-
305
- # if the starting_reference column letters are the same with ending_reference
306
- # use the first one otherwise use both
307
- if ending_reference.blank? || starting_reference[/A-Z{1,}/] == ending_reference[/A-Z{1,}/]
308
- starting_reference
309
- else
310
- [starting_reference, ending_reference]
290
+ def sqref_range
291
+ @sqref_range ||= begin
292
+ # "BH5:BH271 BI5:BI271"
293
+ if !sqref.include?(':')
294
+ cell_letter = sqref.gsub(/[\d]/, '')
295
+ index = sqref.gsub(/[^\d]/, '').to_i
296
+ { cell_letter => (index..index)}
297
+ else
298
+ sqref.split( ' ').map do |splitted_by_space_sqref|
299
+ # ["BH5:BH271, "BI5:BI271"]
300
+ if splitted_by_space_sqref.is_a?(Array)
301
+ splitted_by_space_sqref.map do |sqref|
302
+ build_range(splitted_by_space_sqref)
303
+ end
304
+ else
305
+ # "BH5:BH271"
306
+ build_range(splitted_by_space_sqref)
307
+ end
308
+ end.to_h
309
+ end
311
310
  end
312
311
  end
312
+
313
+ def build_range(sqref)
314
+ start_letter, end_letter = sqref.gsub(/[\d]/, '').split(':')
315
+ start_index, end_index = sqref.gsub(/[^\d:]/, '').split(':').map(&:to_i)
316
+ [(start_letter..end_letter),(start_index..end_index)]
317
+ end
313
318
  end
314
319
  end
315
320
  end
@@ -119,7 +119,7 @@ module OOXML
119
119
  class Excel
120
120
  class Styles
121
121
  class Fill
122
- attr_accessor :pattern_type, :fg_color, :fg_color_theme, :fg_color_tint, :bg_color_index, :bg_color
122
+ attr_accessor :pattern_type, :fg_color, :fg_color_theme, :fg_color_tint, :bg_color_index, :bg_color, :fg_color_index
123
123
 
124
124
  def initialize(**attrs)
125
125
  attrs.each { |property, value| send("#{property}=", value)}
@@ -131,12 +131,15 @@ module OOXML
131
131
  if pattern_type == "solid"
132
132
  fg_color = pattern_fill.at('fgColor')
133
133
  bg_color = pattern_fill.at('bgColor')
134
+ fg_color_index = fg_color.class == Nokogiri::XML::Element ? fg_color.attributes["indexed"].try(:value) : nil
135
+
134
136
  self.new(pattern_type: pattern_type,
135
137
  fg_color: (fg_color.present?) ? fg_color.attributes["rgb"].try(:value) : nil,
136
138
  fg_color_theme: (fg_color.present?) ? fg_color.attributes["theme"].try(:value) : nil,
137
139
  fg_color_tint: (fg_color.present?) ? fg_color.attributes["tint"].try(:value) : nil,
138
140
  bg_color: (bg_color.present?) ? bg_color.attributes["rgb"].try(:value) : nil,
139
- bg_color_index: (bg_color.present?) ? bg_color.attributes["index"].try(:value) : nil)
141
+ bg_color_index: (bg_color.present?) ? bg_color.attributes["index"].try(:value) : nil,
142
+ fg_color_index: fg_color_index)
140
143
  else
141
144
  self.new(pattern_type: pattern_type)
142
145
  end
@@ -1,5 +1,5 @@
1
1
  module OOXML
2
2
  class Excel
3
- VERSION = "0.0.3.3"
3
+ VERSION = "0.0.3.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxml_excel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.3
4
+ version: 0.0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mones
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-04 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.4.5.1
147
+ rubygems_version: 2.6.4
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: OOXML Excel - Parse Excel Spreadsheets (xlsx, xlsm).