rusk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -5,7 +5,7 @@
5
5
  guard 'rspec', :cli => '--color', :all_after_pass => false, :all_on_start => false do
6
6
  watch(%r{^spec/.+_spec\.rb$})
7
7
  watch(%r{^lib/rusk/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
- watch('lib/goblin.rb') { "spec" }
8
+ watch('lib/rusk.rb') { "spec" }
9
9
  watch('spec/spec_helper.rb') { "spec" }
10
10
  end
11
11
 
data/README.md CHANGED
@@ -98,6 +98,16 @@ Rusk::Sheet#each_column
98
98
  end
99
99
  ```
100
100
 
101
+ If Rusk::Sheet#each, each_row, each_column call without block, return Enumerator instance
102
+
103
+ ```ruby
104
+ sheet.each_row # return Enumerator
105
+
106
+ # use method chain
107
+ sheet.each_row.with_index |rows, index|
108
+ end
109
+ ```
110
+
101
111
  #### cell's value ####
102
112
 
103
113
  Rusk::Cell#value gets the value of the cell according to the format.
@@ -7,16 +7,10 @@ module Rusk
7
7
  def initialize(content)
8
8
  @content = content
9
9
  @cells = []
10
- @content.xpath('.//table:table-row').each do |row_range|
11
- row_cells = []
12
- row_range.xpath(".//table:table-cell|.//table:covered-table-cell").each do |cell|
13
- row_cells << Rusk::Cell.new(cell)
14
- (cell["table:number-columns-repeated"].to_i - 1).times do
15
- row_cells << Rusk::Cell.new(cell)
16
- end
17
- end
18
- @cells << row_cells
19
- end
10
+ rows = @content.xpath('.//table:table-row')
11
+ @row_size = rows.select { |row| row["table:number-rows-repeated"] }.inject(0) { |sum, item| sum + item["table:number-rows-repeated"].to_i} + rows.size
12
+ columns = rows[0].xpath(".//table:table-cell|.//table:covered-table-cell")
13
+ @column_size = columns.select{ |cell| cell["table:number-columns-repeated"] }.inject(0){ |sum, item| sum + item["table:number-columns-repeated"].to_i } + columns.size
20
14
  end
21
15
 
22
16
  def name
@@ -28,29 +22,88 @@ module Rusk
28
22
  end
29
23
 
30
24
  def [](row, column)
31
- return nil if row > @cells.size || column > @cells[0].size
25
+ return nil if @row_size < row || @column_size < column
26
+ return @cells[row][column] if @cells[row]
27
+
28
+ row_index = 0
29
+ each_row(force: true) do |row_range|
30
+ break if row_index > row
31
+ row_index += 1
32
+ end
33
+
32
34
  @cells[row][column]
33
35
  end
34
36
 
35
- def each
36
- @cells.each do |rows|
37
- rows.each do |cell|
37
+ def each(&block)
38
+ return Enumerator.new(self) unless block
39
+ each_row do |row_range|
40
+ row_range.each do |cell|
38
41
  yield cell
39
42
  end
40
43
  end
41
44
  end
42
45
 
43
- def each_row
44
- @cells.each do |rows|
45
- yield rows
46
+ def each_row(options = {force: false}, &block)
47
+ return Enumerator.new(self, :each_row) unless block
48
+ row_index = 0
49
+ @content.xpath('.//table:table-row').each_with_index do |row_range, index|
50
+ if @cells[row_index]
51
+ yield @cells[row_index]
52
+ row_index += 1
53
+ next
54
+ end
55
+ rows_repeated = row_range["table:number-rows-repeated"].to_i
56
+ break if rows_repeated + row_index + 1 >= 1048576 && options[:force] == false
57
+
58
+ cells = row_cells(row_range)
59
+ yield cells
60
+ @cells << cells
61
+ row_index += 1
62
+
63
+ if rows_repeated > 1
64
+ base_row_range = row_range
65
+ (rows_repeated - 1).times do |i|
66
+ base_row_range.remove_attribute("number-rows-repeated")
67
+ base_row_range = base_row_range.add_next_sibling(row_range.dup)
68
+ base_row_range["table:number-rows-repeated"] = (rows_repeated - i)
69
+ cells = row_cells(base_row_range)
70
+ yield cells
71
+ @cells << cells
72
+ row_index += 1
73
+ end
74
+ end
46
75
  end
47
76
  end
48
77
 
49
- def each_column
78
+ def each_column(&block)
79
+ return Enumerator.new(self, :each_column) unless block
80
+ self.each_row{|i| i}
50
81
  @cells.transpose.each do |columns|
51
82
  yield columns
52
83
  end
53
84
  end
54
85
 
86
+ private
87
+ def row_cells(row_range)
88
+ row_cells = []
89
+ row_range.xpath(".//table:table-cell|.//table:covered-table-cell").each_with_index do |cell, index|
90
+ number_repeated = cell["table:number-columns-repeated"].to_i
91
+ break if number_repeated + index >= 1024
92
+
93
+ row_cells << Rusk::Cell.new(cell)
94
+
95
+ if number_repeated > 1
96
+ cell.remove_attribute("number-columns-repeated")
97
+ base_cell = cell
98
+ (number_repeated - 1).times do
99
+ base_cell = base_cell.add_next_sibling(cell.dup)
100
+ row_cells << Rusk::Cell.new(base_cell)
101
+ end
102
+ end
103
+ end
104
+
105
+ row_cells
106
+ end
107
+
55
108
  end
56
109
  end
@@ -1,3 +1,3 @@
1
1
  module Rusk
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,63 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
3
+ <office:scripts/>
4
+ <office:font-face-decls>
5
+ <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/>
6
+ <style:font-face style:name="MS Pゴシック" svg:font-family="'MS Pゴシック'" style:font-family-generic="swiss" style:font-pitch="variable"/>
7
+ <style:font-face style:name="Arial Unicode MS" svg:font-family="'Arial Unicode MS'" style:font-family-generic="system" style:font-pitch="variable"/>
8
+ <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system" style:font-pitch="variable"/>
9
+ </office:font-face-decls>
10
+ <office:automatic-styles>
11
+ <style:style style:name="co1" style:family="table-column">
12
+ <style:table-column-properties fo:break-before="auto" style:column-width="2.178cm"/>
13
+ </style:style>
14
+ <style:style style:name="ro1" style:family="table-row">
15
+ <style:table-row-properties style:row-height="0.476cm" fo:break-before="auto" style:use-optimal-row-height="false"/>
16
+ </style:style>
17
+ <style:style style:name="ta1" style:family="table" style:master-page-name="PageStyle_5f_Sheet1">
18
+ <style:table-properties table:display="true" style:writing-mode="lr-tb"/>
19
+ </style:style>
20
+ </office:automatic-styles>
21
+ <office:body>
22
+ <office:spreadsheet>
23
+ <table:calculation-settings table:case-sensitive="false" table:automatic-find-labels="false" table:use-regular-expressions="false">
24
+ <table:iteration table:maximum-difference="0.0001"/>
25
+ </table:calculation-settings>
26
+ <table:table table:name="Sheet1" table:style-name="ta1">
27
+ <office:forms form:automatic-focus="false" form:apply-design-mode="false"/>
28
+ <table:table-column table:style-name="co1" table:number-columns-repeated="1024" table:default-cell-style-name="Default"/>
29
+ <table:table-row table:style-name="ro1">
30
+ <table:table-cell office:value-type="string">
31
+ <text:p>created</text:p>
32
+ </table:table-cell>
33
+ <table:table-cell table:number-columns-repeated="1023"/>
34
+ </table:table-row>
35
+ <table:table-row table:style-name="ro1">
36
+ <table:table-cell office:value-type="string">
37
+ <text:p>by</text:p>
38
+ </table:table-cell>
39
+ <table:table-cell table:number-columns-repeated="1023"/>
40
+ </table:table-row>
41
+ <table:table-row table:style-name="ro1">
42
+ <table:table-cell office:value-type="string">
43
+ <text:p>excel</text:p>
44
+ </table:table-cell>
45
+ <table:table-cell table:number-columns-repeated="1023"/>
46
+ </table:table-row>
47
+ <table:table-row table:style-name="ro1">
48
+ <table:table-cell office:value-type="float" office:value="2010">
49
+ <text:p>2010</text:p>
50
+ </table:table-cell>
51
+ <table:table-cell table:number-columns-repeated="1023"/>
52
+ </table:table-row>
53
+ <table:table-row table:style-name="ro1" table:number-rows-repeated="1048571">
54
+ <table:table-cell table:number-columns-repeated="1024"/>
55
+ </table:table-row>
56
+ <table:table-row table:style-name="ro1">
57
+ <table:table-cell table:number-columns-repeated="1024"/>
58
+ </table:table-row>
59
+ </table:table>
60
+ <table:named-expressions/>
61
+ </office:spreadsheet>
62
+ </office:body>
63
+ </office:document-content>
Binary file
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
2
+ <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
3
3
  <office:scripts/>
4
4
  <office:font-face-decls>
5
5
  <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/>
@@ -11,9 +11,18 @@
11
11
  <style:style style:name="co1" style:family="table-column">
12
12
  <style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/>
13
13
  </style:style>
14
- <style:style style:name="ro2" style:family="table-row">
14
+ <style:style style:name="co2" style:family="table-column">
15
+ <style:table-column-properties fo:break-before="auto" style:column-width="2.258cm"/>
16
+ </style:style>
17
+ <style:style style:name="ro1" style:family="table-row">
15
18
  <style:table-row-properties style:row-height="0.448cm" fo:break-before="auto" style:use-optimal-row-height="true"/>
16
19
  </style:style>
20
+ <style:style style:name="ro2" style:family="table-row">
21
+ <style:table-row-properties style:row-height="0.452cm" fo:break-before="auto" style:use-optimal-row-height="true"/>
22
+ </style:style>
23
+ <style:style style:name="ro3" style:family="table-row">
24
+ <style:table-row-properties style:row-height="0.427cm" fo:break-before="auto" style:use-optimal-row-height="true"/>
25
+ </style:style>
17
26
  <style:style style:name="ta1" style:family="table" style:master-page-name="Default">
18
27
  <style:table-properties table:display="true" style:writing-mode="lr-tb"/>
19
28
  </style:style>
@@ -35,41 +44,44 @@
35
44
  <number:boolean-style style:name="N99">
36
45
  <number:boolean/>
37
46
  </number:boolean-style>
38
- <number:time-style style:name="N5040" number:language="en" number:country="US">
47
+ <number:time-style style:name="N10040" number:language="en" number:country="US">
39
48
  <number:hours number:style="long"/>
40
49
  <number:text>:</number:text>
41
50
  <number:minutes number:style="long"/>
42
51
  </number:time-style>
43
- <number:date-style style:name="N5076" number:language="en" number:country="US" number:automatic-order="true">
52
+ <number:date-style style:name="N10076" number:language="en" number:country="US" number:automatic-order="true">
44
53
  <number:month number:style="long" number:textual="true"/>
45
54
  <number:text> </number:text>
46
55
  <number:day/>
47
56
  <number:text>, </number:text>
48
57
  <number:year number:style="long"/>
49
58
  </number:date-style>
50
- <number:currency-style style:name="N5104P0" style:volatile="true" number:language="en" number:country="US">
59
+ <number:currency-style style:name="N10104P0" style:volatile="true" number:language="en" number:country="US">
51
60
  <number:currency-symbol number:language="en" number:country="US">$</number:currency-symbol>
52
61
  <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
53
62
  </number:currency-style>
54
- <number:currency-style style:name="N5104" number:language="en" number:country="US">
63
+ <number:currency-style style:name="N10104" number:language="en" number:country="US">
55
64
  <style:text-properties fo:color="#ff0000"/>
56
65
  <number:text>-</number:text>
57
66
  <number:currency-symbol number:language="en" number:country="US">$</number:currency-symbol>
58
67
  <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
59
- <style:map style:condition="value()&gt;=0" style:apply-style-name="N5104P0"/>
68
+ <style:map style:condition="value()&gt;=0" style:apply-style-name="N10104P0"/>
60
69
  </number:currency-style>
61
- <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N5076"/>
62
- <style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N5040"/>
70
+ <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N10076"/>
71
+ <style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N10040"/>
63
72
  <style:style style:name="ce3" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N10"/>
64
73
  <style:style style:name="ce4" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N51"/>
65
74
  <style:style style:name="ce5" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N99"/>
66
- <style:style style:name="ce6" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N5104"/>
75
+ <style:style style:name="ce6" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N10104"/>
76
+ <style:style style:name="ce7" style:family="table-cell" style:parent-style-name="Default">
77
+ <style:table-cell-properties fo:border="0.06pt solid #000000"/>
78
+ </style:style>
67
79
  </office:automatic-styles>
68
80
  <office:body>
69
81
  <office:spreadsheet>
70
82
  <table:table table:name="Sheet1" table:style-name="ta1">
71
83
  <table:table-column table:style-name="co1" table:number-columns-repeated="3" table:default-cell-style-name="Default"/>
72
- <table:table-row table:style-name="ro2">
84
+ <table:table-row table:style-name="ro1">
73
85
  <table:table-cell office:value-type="string">
74
86
  <text:p>string</text:p>
75
87
  </table:table-cell>
@@ -78,7 +90,7 @@
78
90
  </table:table-cell>
79
91
  <table:table-cell/>
80
92
  </table:table-row>
81
- <table:table-row table:style-name="ro2">
93
+ <table:table-row table:style-name="ro1">
82
94
  <table:table-cell office:value-type="string">
83
95
  <text:p>date</text:p>
84
96
  </table:table-cell>
@@ -87,7 +99,7 @@
87
99
  </table:table-cell>
88
100
  <table:table-cell/>
89
101
  </table:table-row>
90
- <table:table-row table:style-name="ro2">
102
+ <table:table-row table:style-name="ro1">
91
103
  <table:table-cell office:value-type="string">
92
104
  <text:p>time</text:p>
93
105
  </table:table-cell>
@@ -96,7 +108,7 @@
96
108
  </table:table-cell>
97
109
  <table:table-cell/>
98
110
  </table:table-row>
99
- <table:table-row table:style-name="ro2">
111
+ <table:table-row table:style-name="ro1">
100
112
  <table:table-cell office:value-type="string">
101
113
  <text:p>float</text:p>
102
114
  </table:table-cell>
@@ -105,7 +117,7 @@
105
117
  </table:table-cell>
106
118
  <table:table-cell/>
107
119
  </table:table-row>
108
- <table:table-row table:style-name="ro2">
120
+ <table:table-row table:style-name="ro1">
109
121
  <table:table-cell office:value-type="string" table:number-columns-spanned="2" table:number-rows-spanned="1">
110
122
  <text:p>merged_cell</text:p>
111
123
  </table:table-cell>
@@ -114,7 +126,7 @@
114
126
  <text:p>after merged column</text:p>
115
127
  </table:table-cell>
116
128
  </table:table-row>
117
- <table:table-row table:style-name="ro2">
129
+ <table:table-row table:style-name="ro1">
118
130
  <table:table-cell office:value-type="string" table:number-columns-spanned="1" table:number-rows-spanned="2">
119
131
  <text:p>merged_row cell</text:p>
120
132
  </table:table-cell>
@@ -123,36 +135,36 @@
123
135
  </table:table-cell>
124
136
  <table:table-cell/>
125
137
  </table:table-row>
126
- <table:table-row table:style-name="ro2">
138
+ <table:table-row table:style-name="ro1">
127
139
  <table:covered-table-cell/>
128
140
  <table:table-cell office:value-type="string">
129
141
  <text:p>merged second row cell</text:p>
130
142
  </table:table-cell>
131
143
  <table:table-cell/>
132
144
  </table:table-row>
133
- <table:table-row table:style-name="ro2">
145
+ <table:table-row table:style-name="ro1">
134
146
  <table:table-cell office:value-type="string">
135
147
  <text:p>after merged row cell</text:p>
136
148
  </table:table-cell>
137
149
  <table:table-cell table:number-columns-repeated="2"/>
138
150
  </table:table-row>
139
- <table:table-row table:style-name="ro2">
151
+ <table:table-row table:style-name="ro1">
140
152
  <table:table-cell table:number-columns-repeated="3"/>
141
153
  </table:table-row>
142
- <table:table-row table:style-name="ro2">
154
+ <table:table-row table:style-name="ro1">
143
155
  <table:table-cell office:value-type="string">
144
156
  <text:p>after blank row</text:p>
145
157
  </table:table-cell>
146
158
  <table:table-cell table:number-columns-repeated="2"/>
147
159
  </table:table-row>
148
- <table:table-row table:style-name="ro2">
160
+ <table:table-row table:style-name="ro1">
149
161
  <table:table-cell/>
150
162
  <table:table-cell office:value-type="string">
151
163
  <text:p>after blank column</text:p>
152
164
  </table:table-cell>
153
165
  <table:table-cell/>
154
166
  </table:table-row>
155
- <table:table-row table:style-name="ro2">
167
+ <table:table-row table:style-name="ro1">
156
168
  <table:table-cell office:value-type="string" table:number-columns-spanned="2" table:number-rows-spanned="1">
157
169
  <text:p>hide the cell next to</text:p>
158
170
  </table:table-cell>
@@ -161,7 +173,7 @@
161
173
  </table:covered-table-cell>
162
174
  <table:table-cell/>
163
175
  </table:table-row>
164
- <table:table-row table:style-name="ro2">
176
+ <table:table-row table:style-name="ro1">
165
177
  <table:table-cell office:value-type="string">
166
178
  <text:p>percentage</text:p>
167
179
  </table:table-cell>
@@ -170,7 +182,7 @@
170
182
  </table:table-cell>
171
183
  <table:table-cell/>
172
184
  </table:table-row>
173
- <table:table-row table:style-name="ro2">
185
+ <table:table-row table:style-name="ro1">
174
186
  <table:table-cell office:value-type="string">
175
187
  <text:p>enter date of time</text:p>
176
188
  </table:table-cell>
@@ -179,7 +191,7 @@
179
191
  </table:table-cell>
180
192
  <table:table-cell/>
181
193
  </table:table-row>
182
- <table:table-row table:style-name="ro2">
194
+ <table:table-row table:style-name="ro1">
183
195
  <table:table-cell office:value-type="string">
184
196
  <text:p>boolean</text:p>
185
197
  </table:table-cell>
@@ -190,7 +202,7 @@
190
202
  <text:p>FALSE</text:p>
191
203
  </table:table-cell>
192
204
  </table:table-row>
193
- <table:table-row table:style-name="ro2">
205
+ <table:table-row table:style-name="ro1">
194
206
  <table:table-cell office:value-type="string">
195
207
  <text:p>currency</text:p>
196
208
  </table:table-cell>
@@ -200,18 +212,31 @@
200
212
  <table:table-cell/>
201
213
  </table:table-row>
202
214
  </table:table>
203
- <table:table table:name="Sheet2" table:style-name="ta1">
204
- <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
205
- <table:table-row table:style-name="ro2">
206
- <table:table-cell/>
215
+ <table:table table:name="rows-repeated" table:style-name="ta1">
216
+ <table:table-column table:style-name="co1" table:default-cell-style-name="ce7"/>
217
+ <table:table-column table:style-name="co2" table:default-cell-style-name="ce7"/>
218
+ <table:table-row table:style-name="ro3">
219
+ <table:table-cell office:value-type="string">
220
+ <text:p>title1</text:p>
221
+ </table:table-cell>
222
+ <table:table-cell office:value-type="string">
223
+ <text:p>title2</text:p>
224
+ </table:table-cell>
225
+ </table:table-row>
226
+ <table:table-row table:style-name="ro3" table:number-rows-repeated="10">
227
+ <table:table-cell table:number-columns-repeated="2"/>
228
+ </table:table-row>
229
+ <table:table-row table:style-name="ro3">
230
+ <table:table-cell table:number-columns-repeated="2"/>
207
231
  </table:table-row>
208
232
  </table:table>
209
233
  <table:table table:name="Sheet3" table:style-name="ta1">
210
234
  <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
211
- <table:table-row table:style-name="ro2">
235
+ <table:table-row table:style-name="ro1">
212
236
  <table:table-cell/>
213
237
  </table:table-row>
214
238
  </table:table>
239
+ <table:named-expressions/>
215
240
  </office:spreadsheet>
216
241
  </office:body>
217
242
  </office:document-content>
@@ -3,60 +3,111 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
3
 
4
4
  describe Rusk::Sheet do
5
5
  before do
6
- content = Nokogiri::XML(File.read("#{dir}/general_datas_content.xml"))
7
- @sheet = Rusk::Sheet.new(content.xpath("//table:table")[0])
8
- @cells = [
9
- ["string", "mruby", ""],
10
- ["date", Date.new(2012,04,29), ""],
11
- ["time", "16:50", ""],
12
- ["float", 7000.0, ""],
13
- ["merged_cell", "", "after merged column"],
14
- ["merged_row cell", "merged first row cell", ""],
15
- ["", "merged second row cell", ""],
16
- ["after merged row cell", "", ""],
17
- ["", "", ""],
18
- ["after blank row", "", ""],
19
- ["", "after blank column", ""],
20
- ["hide the cell next to", "hidden cell", ""],
21
- ["percentage", 0.1, ""],
22
- ["enter date of time", DateTime.new(2012,5,26,18,17), ""],
23
- ["boolean", true, false],
24
- ["currency", 10.0, ""]
25
- ]
6
+ @content = Nokogiri::XML(File.read("#{dir}/general_datas_content.xml"))
7
+ end
8
+
9
+ shared_context "read Sheet1" do
10
+ before do
11
+ @sheet = Rusk::Sheet.new(@content.xpath("//table:table")[0])
12
+ @cells = [
13
+ ["string", "mruby", ""],
14
+ ["date", Date.new(2012,04,29), ""],
15
+ ["time", "16:50", ""],
16
+ ["float", 7000.0, ""],
17
+ ["merged_cell", "", "after merged column"],
18
+ ["merged_row cell", "merged first row cell", ""],
19
+ ["", "merged second row cell", ""],
20
+ ["after merged row cell", "", ""],
21
+ ["", "", ""],
22
+ ["after blank row", "", ""],
23
+ ["", "after blank column", ""],
24
+ ["hide the cell next to", "hidden cell", ""],
25
+ ["percentage", 0.1, ""],
26
+ ["enter date of time", DateTime.new(2012,5,26,18,17), ""],
27
+ ["boolean", true, false],
28
+ ["currency", 10.0, ""]
29
+ ]
30
+ end
31
+ end
32
+
33
+ shared_context "read rows-repeated" do
34
+ before do
35
+ @sheet = Rusk::Sheet.new(@content.xpath("//table:table")[1])
36
+ @cells = [
37
+ ["title1", "title2"],
38
+ ["", ""],
39
+ ["", ""],
40
+ ["", ""],
41
+ ["", ""],
42
+ ["", ""],
43
+ ["", ""],
44
+ ["", ""],
45
+ ["", ""],
46
+ ["", ""],
47
+ ["", ""],
48
+ ["", ""]
49
+ ]
50
+ end
51
+ end
52
+
53
+ shared_context "read file created from excel 2010" do
54
+ before do
55
+ content = Nokogiri::XML(File.read("#{dir}/created_from_excel2010_content.xml"))
56
+ @sheet = Rusk::Sheet.new(content.xpath("//table:table")[0])
57
+ @cells = [["created"], ["by"], ["excel"], [2010.0]]
58
+ end
26
59
  end
27
60
 
28
61
  describe "#name" do
62
+ include_context "read Sheet1"
29
63
  it { @sheet.name.should eq "Sheet1" }
30
64
  end
31
65
 
32
66
  describe "#[]" do
33
- context "with exist cell index" do
34
- it { @sheet[2, 1].should be_kind_of Rusk::Cell }
35
- it { @sheet[0, 0].value.should eq "string" }
36
- it { @sheet[0, 1].value.should eq "mruby" }
37
- it { @sheet[1, 1].value.should eq Date.new(2012,4,29) }
38
- it { @sheet[4, 2].value.should eq 'after merged column' }
39
- it { @sheet[5, 1].value.should eq 'merged first row cell' }
40
- it { @sheet[6, 1].value.should eq 'merged second row cell' }
41
- it { @sheet[8, 0].value.should eq "" }
42
- it { @sheet[8, 1].value.should eq "" }
43
- it { @sheet[11, 0].value.should eq 'hide the cell next to' }
44
- it { @sheet[11, 1].value.should eq 'hidden cell' }
45
- end
46
-
47
- context "with not exist cell index" do
48
- context "when row is existing, column is not existing" do
49
- it { @sheet[0, 1000].should be_nil }
67
+ context "read Sheet1(merged, columns-repeated, various data type)" do
68
+ include_context "read Sheet1"
69
+ context "with exist cell index" do
70
+ it { @sheet[2, 1].should be_kind_of Rusk::Cell }
71
+ it { @sheet[0, 0].value.should eq "string" }
72
+ it { @sheet[0, 1].value.should eq "mruby" }
73
+ it { @sheet[1, 1].value.should eq Date.new(2012,4,29) }
74
+ it { @sheet[4, 2].value.should eq 'after merged column' }
75
+ it { @sheet[5, 1].value.should eq 'merged first row cell' }
76
+ it { @sheet[6, 1].value.should eq 'merged second row cell' }
77
+ it { @sheet[8, 0].value.should eq "" }
78
+ it { @sheet[8, 1].value.should eq "" }
79
+ it { @sheet[11, 0].value.should eq 'hide the cell next to' }
80
+ it { @sheet[11, 1].value.should eq 'hidden cell' }
50
81
  end
51
82
 
52
- context "when row and column is not existing" do
53
- it { @sheet[1000, 10000].should be_nil }
83
+ context "with not exist cell index" do
84
+ context "when row is existing, column is not existing" do
85
+ it { @sheet[0, 1000].should be_nil }
86
+ end
87
+
88
+ context "when row and column is not existing" do
89
+ it { @sheet[1000, 10000].should be_nil }
90
+ end
54
91
  end
55
92
  end
56
93
 
94
+ context "read rows-repeated" do
95
+ include_context "read rows-repeated"
96
+ it { @sheet.map(&:value).should have(24).items }
97
+ it { @sheet.map(&:value).should eq @cells.flatten }
98
+ end
99
+
100
+ context "read created_from_excel2010" do
101
+ include_context "read file created from excel 2010"
102
+ it { @sheet[0, 0].value.should eq "created" }
103
+ it { @sheet[1, 0].value.should eq "by" }
104
+ it { @sheet.map(&:value).should eq @cells.flatten }
105
+ end
106
+
57
107
  end
58
108
 
59
109
  describe "#each" do
110
+ include_context "read Sheet1"
60
111
  it "access order by row and column" do
61
112
  cells = @cells.flatten
62
113
  index = 0
@@ -64,20 +115,55 @@ describe Rusk::Sheet do
64
115
  cell.value.should eq cells[index]
65
116
  index += 1
66
117
  end
118
+
119
+ index.should eq cells.size
120
+ end
121
+
122
+ context "without block" do
123
+ it { @sheet.each.should be_kind_of Enumerator }
67
124
  end
68
125
  end
69
126
 
70
127
  describe "#each_row" do
71
- it "access order by first row" do
72
- index = 0
73
- @sheet.each_row do |rows|
74
- rows.map(&:value).should eq @cells[index]
75
- index += 1
128
+ shared_examples "Sheet#each_row access order by first row" do
129
+ it "access order by first row" do
130
+ index = 0
131
+ @sheet.each_row do |rows|
132
+ rows.map(&:value).should eq @cells[index]
133
+ index += 1
134
+ end
135
+
136
+ index.should eq @cells.size
76
137
  end
77
138
  end
139
+
140
+ context "read Sheet1 of general_datas.ods" do
141
+ include_context "read Sheet1"
142
+ it_behaves_like "Sheet#each_row access order by first row"
143
+ end
144
+
145
+ context "read file created from excel" do
146
+ include_context "read file created from excel 2010"
147
+ it_behaves_like "Sheet#each_row access order by first row"
148
+
149
+ context "once call Sheet#each_row" do
150
+ before do
151
+ @sheet.each_row do |cell|
152
+ end
153
+ end
154
+
155
+ it_behaves_like "Sheet#each_row access order by first row"
156
+ end
157
+ end
158
+
159
+ context "without block" do
160
+ include_context "read Sheet1"
161
+ it { @sheet.each_row.should be_kind_of Enumerator }
162
+ end
78
163
  end
79
164
 
80
165
  describe "#each_column" do
166
+ include_context "read Sheet1"
81
167
  it "access order by first column" do
82
168
  index = 0
83
169
  cells = @cells.transpose
@@ -85,6 +171,11 @@ describe Rusk::Sheet do
85
171
  columns.map(&:value).should eq cells[index]
86
172
  index += 1
87
173
  end
174
+ index.should eq cells.size
175
+ end
176
+
177
+ context "without block" do
178
+ it { @sheet.each_column.should be_kind_of Enumerator }
88
179
  end
89
180
  end
90
181
 
@@ -110,6 +201,46 @@ describe Rusk::Sheet do
110
201
  it { @book[1].name.should eq "changed" }
111
202
  end
112
203
  end
204
+
205
+ context "read rows-repeated" do
206
+ before do
207
+ Rusk::Book.open(@tmp_file) do |book|
208
+ sheet = book[1]
209
+ sheet[1, 1].value = "modified 1,1"
210
+ sheet[2, 1].value = "modified 2,1"
211
+ sheet[3, 0].value = "modified 3,0"
212
+ sheet[3, 1].value = "modified 3,1"
213
+ sheet[11, 1].value = "modified 11,1"
214
+ sheet[5, 1].value = "modified 5,1"
215
+ book.save
216
+ end
217
+ @sheet = Rusk::Book.open(@tmp_file)[1]
218
+ end
219
+
220
+ it { @sheet[1,0].value.should eq "" }
221
+ it { @sheet[1,1].value.should eq "modified 1,1" }
222
+ it { @sheet[2,0].value.should eq "" }
223
+ it { @sheet[2,1].value.should eq "modified 2,1" }
224
+ it { @sheet[3,0].value.should eq "modified 3,0" }
225
+ it { @sheet[3,1].value.should eq "modified 3,1" }
226
+ it { @sheet[4,0].value.should eq "" }
227
+ it { @sheet[4,1].value.should eq "" }
228
+ it { @sheet[5,0].value.should eq "" }
229
+ it { @sheet[5,1].value.should eq "modified 5,1" }
230
+ it { @sheet[6,0].value.should eq "" }
231
+ it { @sheet[6,1].value.should eq "" }
232
+ it { @sheet[7,0].value.should eq "" }
233
+ it { @sheet[7,1].value.should eq "" }
234
+ it { @sheet[8,0].value.should eq "" }
235
+ it { @sheet[8,1].value.should eq "" }
236
+ it { @sheet[9,0].value.should eq "" }
237
+ it { @sheet[9,1].value.should eq "" }
238
+ it { @sheet[10,0].value.should eq "" }
239
+ it { @sheet[10,1].value.should eq "" }
240
+ it { @sheet[11,0].value.should eq "" }
241
+ it { @sheet[11,1].value.should eq "modified 11,1" }
242
+
243
+ end
113
244
  end
114
245
 
115
246
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-22 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
@@ -178,6 +178,8 @@ files:
178
178
  - rusk.gemspec
179
179
  - spec/book_spec.rb
180
180
  - spec/cell_spec.rb
181
+ - spec/data/created_from_excel2010.ods
182
+ - spec/data/created_from_excel2010_content.xml
181
183
  - spec/data/general_datas.ods
182
184
  - spec/data/general_datas_content.xml
183
185
  - spec/sheet_spec.rb
@@ -196,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
198
  version: '0'
197
199
  segments:
198
200
  - 0
199
- hash: -883949039905815181
201
+ hash: -564749220511002682
200
202
  required_rubygems_version: !ruby/object:Gem::Requirement
201
203
  none: false
202
204
  requirements:
@@ -205,16 +207,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
207
  version: '0'
206
208
  segments:
207
209
  - 0
208
- hash: -883949039905815181
210
+ hash: -564749220511002682
209
211
  requirements: []
210
212
  rubyforge_project:
211
- rubygems_version: 1.8.24
213
+ rubygems_version: 1.8.23
212
214
  signing_key:
213
215
  specification_version: 3
214
216
  summary: Read and write Open Document Spreadsheet Format(ods).
215
217
  test_files:
216
218
  - spec/book_spec.rb
217
219
  - spec/cell_spec.rb
220
+ - spec/data/created_from_excel2010.ods
221
+ - spec/data/created_from_excel2010_content.xml
218
222
  - spec/data/general_datas.ods
219
223
  - spec/data/general_datas_content.xml
220
224
  - spec/sheet_spec.rb