ods 0.1.0 → 0.1.1

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: 42adc8c8dec7bc687e86198883d2616891e2fe88
4
- data.tar.gz: a2015c1269f31acf444ca3a4fee01850e718afeb
3
+ metadata.gz: d576b00862b3c7930a90bde429c4811f62888e7e
4
+ data.tar.gz: 66c1c954cf7ffc8f2000d6b4909691b0655144ff
5
5
  SHA512:
6
- metadata.gz: 441b4d3d76316a7761532d3f54524fd0236ee2524b7c5e00bb4009044a6c7b1113c3fbe33a875b3c2e674fe9d8ecb88098012e6ce46e568c507a80cc528c89ef
7
- data.tar.gz: 261923e9398914e2ba64c38b4acab295a53bd63f56676a128cb24f9791e2291bbb774264d90f85cc3f8ecd095aa0c6fde518bdb868120417e19cc8d021529788
6
+ metadata.gz: 60555f224e2bb4b45e398daf13a267630d68659fb275d69f8d0bba78297d1d0b6662a8a0f45f85d7a6a7a9edca054cb57262cb07d220aca4f620b4ee569a3000
7
+ data.tar.gz: 169d2db2864c75d62468537af58f45074db4bd3b3e5648cb4968737e2483a84311e57bec89c9c81835bb8a00c559c87eca8b85188de355fbbcf075a75077e705
@@ -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
@@ -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 = rows[row_index]
16
- if row.kind_of?(Array)
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 = Row.new(node, self)
28
- repeat = node['table:number-rows-repeated'] || 1
29
- repeat.to_i.times do
30
- @rows << a_row
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
- rows.each do |row|
39
- csv << row.cols.map(&:value)
40
- end
40
+ data.each { |row| csv << row }
41
41
  end
42
42
  end
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module Ods
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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].value.should == 'A' }
20
- it { sheet[0,0].value.should be_kind_of(String) }
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].value.should == s
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].value.should == Date.new(2011, 1, i) }
34
- it { sheet[1,i-1].value.should be_kind_of(Date) }
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].value.should == i }
41
- it { sheet[2,i-1].value.should be_kind_of(Fixnum) }
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].value.should == i }
48
- it { sheet[3,i-1].value.should be_kind_of(Fixnum) }
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].value.should == 0 }
54
- it { sheet[4,0].value.should be_kind_of(Fixnum) }
53
+ it { sheet[4, 0].should == 0 }
54
+ it { sheet[4, 0].should be_kind_of(Fixnum) }
55
55
 
56
- it { sheet[4,1].value.should == -1.1 }
57
- it { sheet[4,1].value.should be_kind_of(Float) }
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].value.should == 2.2 }
60
- it { sheet[4,2].value.should be_kind_of(Float) }
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].value.should == 3 }
63
- it { sheet[4,3].value.should be_kind_of(Fixnum) }
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].value.should == true }
68
- it { sheet[5,0].value.should be_kind_of(TrueClass) }
67
+ it { sheet[5, 0].should == true }
68
+ it { sheet[5, 0].should be_kind_of(TrueClass) }
69
69
 
70
- it { sheet[5,1].value.should == false }
71
- it { sheet[5,1].value.should be_kind_of(FalseClass) }
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].value.should == "A#{row+1}" }
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].value.should == 'D10' }
96
+ it { sheet[9, 3].should == 'D10' }
97
97
  end
98
98
  end
99
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Park