ods 0.1.0 → 0.1.1
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 +4 -4
- data/lib/ods/row.rb +19 -1
- data/lib/ods/sheet.rb +13 -13
- data/lib/ods/version.rb +1 -1
- data/spec/sheet_spec.rb +25 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d576b00862b3c7930a90bde429c4811f62888e7e
|
4
|
+
data.tar.gz: 66c1c954cf7ffc8f2000d6b4909691b0655144ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60555f224e2bb4b45e398daf13a267630d68659fb275d69f8d0bba78297d1d0b6662a8a0f45f85d7a6a7a9edca054cb57262cb07d220aca4f620b4ee569a3000
|
7
|
+
data.tar.gz: 169d2db2864c75d62468537af58f45074db4bd3b3e5648cb4968737e2483a84311e57bec89c9c81835bb8a00c559c87eca8b85188de355fbbcf075a75077e705
|
data/lib/ods/row.rb
CHANGED
@@ -7,6 +7,10 @@ module Ods
|
|
7
7
|
@sheet = sheet
|
8
8
|
end
|
9
9
|
|
10
|
+
def [](index)
|
11
|
+
data[index]
|
12
|
+
end
|
13
|
+
|
10
14
|
def cols
|
11
15
|
return @cols if @cols
|
12
16
|
@cols = []
|
@@ -19,5 +23,19 @@ module Ods
|
|
19
23
|
end
|
20
24
|
@cols
|
21
25
|
end
|
26
|
+
|
27
|
+
def data
|
28
|
+
@data ||= begin
|
29
|
+
values = if cols.last.value == ''
|
30
|
+
cols.reject { |col| col == cols.last }
|
31
|
+
else
|
32
|
+
cols
|
33
|
+
end.map(&:value)
|
34
|
+
while values.length > 0 && values.last == ''
|
35
|
+
values.pop
|
36
|
+
end
|
37
|
+
values
|
38
|
+
end
|
39
|
+
end
|
22
40
|
end
|
23
|
-
end
|
41
|
+
end
|
data/lib/ods/sheet.rb
CHANGED
@@ -12,32 +12,32 @@ module Ods
|
|
12
12
|
|
13
13
|
# access by (0,0) = top left
|
14
14
|
def [](row_index, col_index)
|
15
|
-
row =
|
16
|
-
|
17
|
-
puts "bad #{row_index} #{col_index}"
|
18
|
-
#puts row
|
19
|
-
end
|
20
|
-
row.nil? ? nil : row.cols[col_index]
|
15
|
+
row = data[row_index]
|
16
|
+
row && row[col_index]
|
21
17
|
end
|
22
18
|
|
23
19
|
def rows
|
24
20
|
return @rows if @rows
|
25
21
|
@rows = []
|
26
22
|
content.xpath('descendant::table:table-row').each do |node|
|
27
|
-
a_row =
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
a_row = Row.new(node, self)
|
24
|
+
if a_row.data.length > 0
|
25
|
+
repeat = node['table:number-rows-repeated'] || 1
|
26
|
+
repeat.to_i.times do
|
27
|
+
@rows << a_row
|
28
|
+
end
|
31
29
|
end
|
32
30
|
end
|
33
31
|
@rows
|
34
32
|
end
|
35
33
|
|
34
|
+
def data
|
35
|
+
@data ||= rows.map(&:data).reject { |row| row.length == 0 }
|
36
|
+
end
|
37
|
+
|
36
38
|
def csv
|
37
39
|
CSV do |csv|
|
38
|
-
|
39
|
-
csv << row.cols.map(&:value)
|
40
|
-
end
|
40
|
+
data.each { |row| csv << row }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/ods/version.rb
CHANGED
data/spec/sheet_spec.rb
CHANGED
@@ -16,63 +16,63 @@ describe Ods::Sheet do
|
|
16
16
|
|
17
17
|
context "basic navigation" do
|
18
18
|
context "first row" do
|
19
|
-
it { sheet[0,0].
|
20
|
-
it { sheet[0,0].
|
19
|
+
it { sheet[0, 0].should == 'A' }
|
20
|
+
it { sheet[0, 0].should be_kind_of(String) }
|
21
21
|
it "have 4 columns" do
|
22
22
|
sheet.rows[0].cols.count.should == 4
|
23
23
|
end
|
24
24
|
it "contains" do
|
25
25
|
%w(A row of strings).each_with_index do |s, i|
|
26
|
-
sheet[0, i].
|
26
|
+
sheet[0, i].should == s
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context "second row" do
|
32
32
|
(1..4).each do |i|
|
33
|
-
it { sheet[1,i-1].
|
34
|
-
it { sheet[1,i-1].
|
33
|
+
it { sheet[1, i-1].should == Date.new(2011, 1, i) }
|
34
|
+
it { sheet[1, i-1].should be_kind_of(Date) }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context "third row integers" do
|
39
39
|
(1..4).each do |i|
|
40
|
-
it { sheet[2,i-1].
|
41
|
-
it { sheet[2,i-1].
|
40
|
+
it { sheet[2, i-1].should == i }
|
41
|
+
it { sheet[2, i-1].should be_kind_of(Fixnum) }
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
context "forth row matches third row" do
|
46
46
|
(1..4).each do |i|
|
47
|
-
it { sheet[3,i-1].
|
48
|
-
it { sheet[3,i-1].
|
47
|
+
it { sheet[3, i-1].should == i }
|
48
|
+
it { sheet[3, i-1].should be_kind_of(Fixnum) }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
context "row five has mixed float&ints" do
|
53
|
-
it { sheet[4,0].
|
54
|
-
it { sheet[4,0].
|
53
|
+
it { sheet[4, 0].should == 0 }
|
54
|
+
it { sheet[4, 0].should be_kind_of(Fixnum) }
|
55
55
|
|
56
|
-
it { sheet[4,1].
|
57
|
-
it { sheet[4,1].
|
56
|
+
it { sheet[4, 1].should == -1.1 }
|
57
|
+
it { sheet[4, 1].should be_kind_of(Float) }
|
58
58
|
|
59
|
-
it { sheet[4,2].
|
60
|
-
it { sheet[4,2].
|
59
|
+
it { sheet[4, 2].should == 2.2 }
|
60
|
+
it { sheet[4, 2].should be_kind_of(Float) }
|
61
61
|
|
62
|
-
it { sheet[4,3].
|
63
|
-
it { sheet[4,3].
|
62
|
+
it { sheet[4, 3].should == 3 }
|
63
|
+
it { sheet[4, 3].should be_kind_of(Fixnum) }
|
64
64
|
end
|
65
65
|
|
66
66
|
context "row 6 has booleans" do
|
67
|
-
it { sheet[5,0].
|
68
|
-
it { sheet[5,0].
|
67
|
+
it { sheet[5, 0].should == true }
|
68
|
+
it { sheet[5, 0].should be_kind_of(TrueClass) }
|
69
69
|
|
70
|
-
it { sheet[5,1].
|
71
|
-
it { sheet[5,1].
|
70
|
+
it { sheet[5, 1].should == false }
|
71
|
+
it { sheet[5, 1].should be_kind_of(FalseClass) }
|
72
72
|
end
|
73
73
|
|
74
74
|
context "out of bounds" do
|
75
|
-
it { sheet[1000,100].should_not be }
|
75
|
+
it { sheet[1000, 100].should_not be }
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -85,15 +85,15 @@ describe Ods::Sheet do
|
|
85
85
|
context "column A" do
|
86
86
|
(0..9).each do |row|
|
87
87
|
context "row #{row}" do
|
88
|
-
it { sheet[row, 0].
|
88
|
+
it { sheet[row, 0].should == "A#{row+1}" }
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
it { sheet[10,0].should_not be }
|
92
|
+
it { sheet[10, 0].should_not be }
|
93
93
|
end
|
94
94
|
|
95
95
|
context "bottom right" do
|
96
|
-
it { sheet[9, 3].
|
96
|
+
it { sheet[9, 3].should == 'D10' }
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|