ooxl 0.0.1.4.8.4 → 0.0.1.4.9

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: d2390c1057acdb0574b122afbb727df765e44cdc
4
- data.tar.gz: 9ce841e16ce3f15fc3c4090b960a9d6b7a2ae87f
3
+ metadata.gz: 48275946ae01a29a5f56c0c1bc561e66650977bb
4
+ data.tar.gz: 6d2a8a0cbbb736813eef27b018195b851098afad
5
5
  SHA512:
6
- metadata.gz: 6af6199d80cf4e363be9104449a6e40a746e9a2374246521115cdf61adfd0f2e1804484a6fe0101de600c85a2e095e5fde39ed3b445b4e7381740fe4b9adfa89
7
- data.tar.gz: 48455f48245053a6aefb95a6561288b3584ea8106801ed9ee47b846fd4a06b55864be6f6d9af6721c1efc21f79db5f2b6f0e2724aefd9d4210f7ac80f08cd003
6
+ metadata.gz: 7e4682b4a534e2334eaf1bd697e05c3adcc521fed4866219269a919bb501dace8621915ab904474a5ab6134457f6271565f6a48edf7e373cc540ef99d435e31b
7
+ data.tar.gz: 64131b1a33db9784767a7f9721dbf97ffa5b44b55fff7ab612191c090480d52fdd3337e051bb89151ca889d11d151a2d0711952371b3edb843d265a9ac4a5ac1
data/lib/ooxl/ooxl.rb CHANGED
@@ -76,7 +76,7 @@ class OOXL
76
76
  case entry.name
77
77
  when /xl\/worksheets\/sheet(\d+)?\.xml/
78
78
  sheet_id = entry.name.scan(/xl\/worksheets\/sheet(\d+)?\.xml/).flatten.first
79
- @sheets[sheet_id] = OOXL::Sheet.new(entry.get_input_stream.read, shared_strings)
79
+ @sheets[sheet_id] = OOXL::Sheet.new(entry.get_input_stream.read, shared_strings, @options)
80
80
  when /xl\/styles\.xml/
81
81
  @styles = OOXL::Styles.load_from_stream(entry.get_input_stream.read)
82
82
  when /xl\/comments(\d+)?\.xml/
data/lib/ooxl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class OOXL
2
- VERSION = "0.0.1.4.8.4"
2
+ VERSION = "0.0.1.4.9"
3
3
  end
@@ -25,6 +25,14 @@ class OOXL
25
25
  attrs.each { |property, value| send("#{property}=", value)}
26
26
  end
27
27
 
28
+ def column
29
+ @column ||= id.gsub(/\d+/, '')
30
+ end
31
+
32
+ def row
33
+ @row ||= id.gsub(/[^\d+]/, '')
34
+ end
35
+
28
36
  def next_id(offset: 1, location: "bottom")
29
37
  _, column_letter, column_index = id.partition(/[A-Z]+/)
30
38
 
@@ -4,7 +4,8 @@ class OOXL
4
4
  attr_accessor :id, :spans, :cells
5
5
 
6
6
  def initialize(**attrs)
7
- attrs.each { |property, value| send("#{property}=", value)}
7
+ attrs.each { |property, value| property == :options ? instance_variable_set("@#{property}", value) : send("#{property}=", value)}
8
+ @options ||= {}
8
9
  end
9
10
 
10
11
  def [](id)
@@ -16,6 +17,19 @@ class OOXL
16
17
  (cell.present?) ? cell : BlankCell.new(id)
17
18
  end
18
19
 
20
+ def cells
21
+ if @options[:padded_cells]
22
+ unless @cells.blank?
23
+ 'A'.upto(@cells.last.column).map do |column_letter|
24
+ cell = @cells.find { |cell| cell.column == column_letter}
25
+ (cell.blank?) ? BlankCell.new("#{column_letter}#{id}") : cell
26
+ end
27
+ end
28
+ else
29
+ @cells
30
+ end
31
+ end
32
+
19
33
  def cell(cell_id)
20
34
  cell_final_id = cell_id[/[A-Z]{1,}\d+/] ? cell_id : "#{cell_id}#{id}"
21
35
  cells.find { |cell| cell.id == cell_final_id}
@@ -25,10 +39,11 @@ class OOXL
25
39
  cells.each { |cell| yield cell }
26
40
  end
27
41
 
28
- def self.load_from_node(row_node, shared_strings, styles)
42
+ def self.load_from_node(row_node, shared_strings, styles, options)
29
43
  new(id: row_node.attributes["r"].try(:value),
30
44
  spans: row_node.attributes["spans"].try(:value),
31
- cells: row_node.xpath('c').map { |cell_node| OOXL::Cell.load_from_node(cell_node, shared_strings, styles) } )
45
+ cells: row_node.xpath('c').map { |cell_node| OOXL::Cell.load_from_node(cell_node, shared_strings, styles)},
46
+ options: options )
32
47
  end
33
48
  end
34
49
  end
@@ -6,13 +6,14 @@ class OOXL
6
6
  attr_reader :columns, :data_validations, :shared_strings
7
7
  attr_accessor :comments, :styles, :defined_names, :name
8
8
 
9
- def initialize(xml, shared_strings)
9
+ def initialize(xml, shared_strings, options={})
10
10
  @xml = Nokogiri.XML(xml).remove_namespaces!
11
11
  @shared_strings = shared_strings
12
12
  @comments = {}
13
13
  @defined_names = {}
14
14
  @styles = []
15
15
  @loaded_cache = {}
16
+ @options = options
16
17
  end
17
18
 
18
19
  def code_name
@@ -80,7 +81,7 @@ class OOXL
80
81
  def rows
81
82
  @rows ||= begin
82
83
  all_rows = @xml.xpath('//sheetData/row').map do |row_node|
83
- row = Row.load_from_node(row_node, @shared_strings, styles)
84
+ row = Row.load_from_node(row_node, @shared_strings, @styles, @options)
84
85
  yield row if block_given?
85
86
  row
86
87
  end
@@ -90,7 +91,14 @@ class OOXL
90
91
  end
91
92
 
92
93
  def each
93
- rows { |row| yield row }
94
+ if @options[:padded_rows]
95
+ (1.upto(rows.size)).each do |row_index|
96
+ row = row(row_index)
97
+ yield (row.blank?) ? Row.new(id: "#{row_index}", cells: []) : row
98
+ end
99
+ else
100
+ rows { |row| yield row }
101
+ end
94
102
  end
95
103
 
96
104
  def font(cell_reference)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.4.8.4
4
+ version: 0.0.1.4.9
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-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport