spreet 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ module Spreet
2
+
3
+ module VERSION
4
+ MAJOR = "0"
5
+ MINOR = "0"
6
+ PATCH = "4"
7
+ STRING = [MAJOR, MINOR, PATCH].join('.').freeze
8
+ end
9
+
10
+ end
data/test/helper.rb CHANGED
@@ -1,12 +1,16 @@
1
- require 'rubygems'
2
- require 'test/unit'
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+
3
4
  require "digest/sha2"
4
5
 
5
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+
7
9
  require 'spreet'
8
10
 
9
- class Test::Unit::TestCase
11
+ FileUtils.mkdir_p("tmp") unless File.exist?("tmp")
12
+
13
+ class SpreetTest < MiniTest::Test
10
14
 
11
15
  def assert_checksums(expected, actual, message=nil)
12
16
  checksums = []
@@ -21,4 +25,22 @@ class Test::Unit::TestCase
21
25
  assert_equal checksums[0], checksums[1], message
22
26
  end
23
27
 
28
+ def assert_nothing_raised(*args, &block)
29
+ yield
30
+ end
31
+
32
+ def assert_raise(exception, *args, &block)
33
+ begin
34
+ yield
35
+ assert false, "No #{exception.name} raised."
36
+ rescue exception => e
37
+ assert e.class == exception, *args
38
+ end
39
+ end
40
+
41
+ def assert_not_nil(value, *args)
42
+ assert !value.nil?, *args
43
+ end
44
+
45
+
24
46
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'helper'
3
3
 
4
- class TestCoordinates < Test::Unit::TestCase
4
+ class TestCoordinates < SpreetTest
5
5
 
6
6
  def test_importations
7
7
  assert_equal Spreet::Coordinates.new(0,0), Spreet::Coordinates.new("A1")
data/test/test_csv.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'helper'
3
3
 
4
- class TestCSV < Test::Unit::TestCase
4
+ class TestCSV < SpreetTest
5
5
 
6
6
  def test_read_and_write
7
- doc = nil
8
- assert_nothing_raised do
9
- doc = Spreet::Document.read("test/samples/pascal.csv")
10
- end
7
+ doc = Spreet::Document.read("test/samples/pascal.csv")
11
8
 
12
9
  sheet = doc.sheets[0]
13
10
  sheet.each_row do |row|
@@ -18,22 +15,16 @@ class TestCSV < Test::Unit::TestCase
18
15
  end
19
16
  end
20
17
 
21
- doc.write("test/samples/cleaned-pascal.csv")
22
-
23
- doc.write("test/samples/cleaned-pascal.xcsv")
24
- doc.write("test/samples/cleaned-pascal-excel.csv", :format=>:xcsv)
25
-
26
- assert_checksums "test/samples/cleaned-pascal.xcsv", "test/samples/cleaned-pascal-excel.csv"
18
+ doc.write("tmp/cleaned-pascal.csv")
27
19
 
28
- assert_nothing_raised do
29
- doc = Spreet::Document.read("test/samples/cleaned-pascal.csv")
30
- end
20
+ doc.write("tmp/cleaned-pascal.xcsv")
21
+ doc.write("tmp/cleaned-pascal-excel.csv", :format=>:xcsv)
31
22
 
32
- assert_nothing_raised do
33
- doc = Spreet::Document.read("test/samples/cleaned-pascal.xcsv")
34
- end
23
+ assert_checksums "tmp/cleaned-pascal.xcsv", "tmp/cleaned-pascal-excel.csv"
35
24
 
36
- FileUtils.rm_f("test/samples/cleaned-pascal*")
25
+ doc = Spreet::Document.read("tmp/cleaned-pascal.csv")
26
+
27
+ doc = Spreet::Document.read("tmp/cleaned-pascal.xcsv")
37
28
  end
38
29
 
39
30
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'helper'
3
3
 
4
- class TestDuration < Test::Unit::TestCase
4
+ class TestDuration < SpreetTest
5
5
 
6
6
  # Test syntax like defined for xsd:duration
7
7
  def test_importations
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'helper'
3
3
 
4
- class TestOpenDocument < Test::Unit::TestCase
4
+ class TestOpenDocument < SpreetTest
5
5
 
6
6
  def test_read_and_write
7
7
  doc = nil
@@ -10,7 +10,7 @@ class TestOpenDocument < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  assert_nothing_raised do
13
- doc.write("test/samples/rewrited-pascal.ods")
13
+ doc.write("tmp/rewrited-pascal.ods")
14
14
  end
15
15
  end
16
16
 
data/test/test_spreet.rb CHANGED
@@ -2,16 +2,13 @@
2
2
  require 'helper'
3
3
  require "digest/sha2"
4
4
 
5
- class TestSpreet < Test::Unit::TestCase
5
+ class TestSpreet < SpreetTest
6
6
 
7
7
  def test_version
8
8
  assert_not_nil Spreet::VERSION
9
9
  assert_not_nil Spreet::VERSION::MAJOR
10
10
  assert_not_nil Spreet::VERSION::MINOR
11
- assert_not_nil Spreet::VERSION::TINY
12
11
  assert_not_nil Spreet::VERSION::PATCH
13
- assert_equal(Spreet::VERSION::TINY, Spreet::VERSION::PATCH, "PATCH code must have the same value as TINY")
14
- assert((Spreet::VERSION::MAJOR > 0 or Spreet::VERSION::MINOR > 0 or Spreet::VERSION::TINY > 0), "Version cannot be 0.0.0")
15
12
  end
16
13
 
17
14
  def test_spreet
@@ -65,14 +62,14 @@ class TestSpreet < Test::Unit::TestCase
65
62
  sheet["F20"] = Date.today
66
63
  sheet["F20"].annotation = "Date.today"
67
64
 
68
- spreet.write("test/samples/cleaned-nothing.ods")
65
+ spreet.write("tmp/cleaned-nothing.ods")
69
66
 
70
- spreet2 = Spreet::Document.read("test/samples/cleaned-nothing.ods")
67
+ spreet2 = Spreet::Document.read("tmp/cleaned-nothing.ods")
71
68
 
72
- spreet2.write("test/samples/cleaned-nothing2.ods")
69
+ spreet2.write("tmp/cleaned-nothing2.ods")
73
70
 
74
71
  # Assert equality of file size ?
75
- assert_checksums "test/samples/cleaned-nothing.ods", "test/samples/cleaned-nothing2.ods", "SHA256 sums differs between the copy and the original. Check if the reader is a good 'mirror' of the writer..."
72
+ assert_checksums "tmp/cleaned-nothing.ods", "tmp/cleaned-nothing2.ods", "SHA256 sums differs between the copy and the original. Check if the reader is a good 'mirror' of the writer..."
76
73
  end
77
74
 
78
75
 
@@ -96,13 +93,13 @@ class TestSpreet < Test::Unit::TestCase
96
93
  assert_equal size-1, sheet.bound.y
97
94
 
98
95
  assert_nothing_raised do
99
- doc.write("test/samples/pascal-tree-#{size}.ods")
96
+ doc.write("tmp/pascal-tree-#{size}.ods")
100
97
  end
101
98
  assert_nothing_raised do
102
- doc.write("test/samples/pascal-tree-#{size}.csv")
99
+ doc.write("tmp/pascal-tree-#{size}.csv")
103
100
  end
104
101
  assert_nothing_raised do
105
- doc.write("test/samples/pascal-tree-#{size}.xcsv")
102
+ doc.write("tmp/pascal-tree-#{size}.xcsv")
106
103
  end
107
104
  end
108
105
 
metadata CHANGED
@@ -1,82 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreet
3
3
  version: !ruby/object:Gem::Version
4
- version: !binary |-
5
- MC4wLjM=
6
- prerelease:
4
+ version: 0.0.4
7
5
  platform: ruby
8
6
  authors:
9
7
  - Brice Texier
10
8
  autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2012-09-05 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
- name: fastercsv
14
+ name: libxml-ruby
17
15
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
16
  requirements:
20
- - - ! '>='
17
+ - - '>='
21
18
  - !ruby/object:Gem::Version
22
19
  version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
23
  requirements:
28
- - - ! '>='
24
+ - - '>='
29
25
  - !ruby/object:Gem::Version
30
26
  version: '0'
31
27
  - !ruby/object:Gem::Dependency
32
- name: libxml-ruby
28
+ name: rubyzip
33
29
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
30
  requirements:
36
- - - ! '>='
31
+ - - '>='
37
32
  - !ruby/object:Gem::Version
38
- version: '0'
33
+ version: 1.0.0
39
34
  type: :runtime
40
35
  prerelease: false
41
36
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
37
  requirements:
44
- - - ! '>='
38
+ - - '>='
45
39
  - !ruby/object:Gem::Version
46
- version: '0'
40
+ version: 1.0.0
47
41
  - !ruby/object:Gem::Dependency
48
- name: rubyzip
42
+ name: money
49
43
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
44
  requirements:
52
- - - ! '>='
45
+ - - '>='
53
46
  - !ruby/object:Gem::Version
54
- version: 0.9.4
47
+ version: 4.0.0
55
48
  type: :runtime
56
49
  prerelease: false
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
51
  requirements:
60
- - - ! '>='
52
+ - - '>='
61
53
  - !ruby/object:Gem::Version
62
- version: 0.9.4
54
+ version: 4.0.0
63
55
  - !ruby/object:Gem::Dependency
64
- name: money
56
+ name: i18n
65
57
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
58
  requirements:
68
- - - ! '>='
59
+ - - <
69
60
  - !ruby/object:Gem::Version
70
- version: 4.0.0
61
+ version: 0.7.0
71
62
  type: :runtime
72
63
  prerelease: false
73
64
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
65
  requirements:
76
- - - ! '>='
66
+ - - <
77
67
  - !ruby/object:Gem::Version
78
- version: 4.0.0
79
- description: Spr[eadsh]eet handler for CSV(RW), Excel CSV(RW) and ODS(W). The goal
68
+ version: 0.7.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>'
102
+ - !ruby/object:Gem::Version
103
+ version: '1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>'
109
+ - !ruby/object:Gem::Version
110
+ version: '1'
111
+ description: Spr[eadsh]eet handler for CSV(RW), Excel CSV(RW) and ODS(RW). The goal
80
112
  is to read and write in many open formats.
81
113
  email: brice.texier@ekylibre.org
82
114
  executables: []
@@ -87,19 +119,23 @@ extra_rdoc_files:
87
119
  files:
88
120
  - MIT-LICENSE
89
121
  - README.rdoc
90
- - VERSION
91
- - lib/big_array.rb
92
122
  - lib/duration.rb
93
123
  - lib/spreet.rb
124
+ - lib/spreet/cell.rb
94
125
  - lib/spreet/coordinates.rb
126
+ - lib/spreet/document.rb
95
127
  - lib/spreet/handlers.rb
128
+ - lib/spreet/handlers/base.rb
96
129
  - lib/spreet/handlers/csv.rb
130
+ - lib/spreet/handlers/excel_csv.rb
97
131
  - lib/spreet/handlers/open_document.rb
132
+ - lib/spreet/sheet.rb
133
+ - lib/spreet/sheets.rb
134
+ - lib/spreet/version.rb
98
135
  - lib/time.rb
99
136
  - test/helper.rb
100
137
  - test/samples/pascal.csv
101
138
  - test/samples/pascal.ods
102
- - test/test_big_array.rb
103
139
  - test/test_coordinates.rb
104
140
  - test/test_csv.rb
105
141
  - test/test_duration.rb
@@ -108,30 +144,28 @@ files:
108
144
  homepage: http://github.com/burisu/spreet
109
145
  licenses:
110
146
  - MIT
147
+ metadata: {}
111
148
  post_install_message:
112
149
  rdoc_options: []
113
150
  require_paths:
114
151
  - lib
115
152
  required_ruby_version: !ruby/object:Gem::Requirement
116
- none: false
117
153
  requirements:
118
- - - ! '>='
154
+ - - '>='
119
155
  - !ruby/object:Gem::Version
120
156
  version: '0'
121
157
  required_rubygems_version: !ruby/object:Gem::Requirement
122
- none: false
123
158
  requirements:
124
- - - ! '>='
159
+ - - '>='
125
160
  - !ruby/object:Gem::Version
126
- version: '0'
161
+ version: 1.9.2
127
162
  requirements: []
128
163
  rubyforge_project:
129
- rubygems_version: 1.8.23
164
+ rubygems_version: 2.0.14
130
165
  signing_key:
131
- specification_version: 3
166
+ specification_version: 4
132
167
  summary: Spr[eadsh]eet handler
133
168
  test_files:
134
- - test/test_big_array.rb
135
169
  - test/test_coordinates.rb
136
170
  - test/test_csv.rb
137
171
  - test/test_duration.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.3
data/lib/big_array.rb DELETED
@@ -1,100 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Class to manage big hash with lot of pairs
4
- class BigArray
5
-
6
- def initialize(klass_name=nil, partition=8, levels=4)
7
- @partition = partition.to_i
8
- raise ArgumentError.new("Partition must be an integer > 0") unless @partition > 0
9
- @levels = levels.to_i
10
- raise ArgumentError.new("Levels must be an integer > 0") unless @levels > 0
11
- klass_name ||= "#{self.class.name}#{@partition}_#{@levels}"
12
- @base_class = "Hash"
13
- code = ""
14
- code << "class #{klass_name}\n"
15
- code << " def initialize()\n"
16
- code << " @root = #{@base_class}.new\n"
17
- code << " end\n\n"
18
-
19
- code << " def [](index)\n"
20
- code << dive do |pointer|
21
- "return nil"
22
- end.strip.gsub(/^/, ' ')+"\n"
23
- code << " return cursor[#{index_at_level(@levels)}]\n"
24
- code << " end\n\n"
25
-
26
- code << " def []=(index, value)\n"
27
- # code << " index, value = args[0], args[1]\n"
28
- code << dive do |pointer|
29
- "#{pointer} = #{@base_class}.new"
30
- end.strip.gsub(/^/, ' ')+"\n"
31
- code << " return cursor[#{index_at_level(@levels)}] = value\n"
32
- code << " end\n\n"
33
-
34
- code << " def delete(index)\n"
35
- # code << " index, value = args[0], args[1]\n"
36
- code << dive do |pointer|
37
- "return nil"
38
- end.strip.gsub(/^/, ' ')+"\n"
39
- code << " return cursor.delete(#{index_at_level(@levels)})\n"
40
- code << " end\n\n"
41
-
42
- code << " def each(&block)\n"
43
- code << browse do
44
- "yield(index, value)"
45
- end.strip.gsub(/^/, ' ')+"\n"
46
- code << " end\n\n"
47
-
48
- code << " def to_hash\n"
49
- code << " hash = {}\n"
50
- code << browse do
51
- "hash[index] = value"
52
- end.strip.gsub(/^/, ' ')+"\n"
53
- code << " return hash\n"
54
- code << " end\n\n"
55
-
56
- code << "end\n"
57
- # raise code
58
- eval(code)
59
- return self.class.const_get(klass_name)
60
- end
61
-
62
- private
63
-
64
- def dive(&block)
65
- code = ""
66
- for level in 1..(@levels-1)
67
- pointer = "#{level == 1 ? '@root' : 'cursor'}[#{index_at_level(level)}]"
68
- code << "unless #{pointer}.is_a?(#{@base_class})\n"
69
- code << yield(pointer).to_s.strip.gsub(/^/, ' ')+"\n"
70
- code << "end\n"
71
- code << "cursor = #{pointer}\n"
72
- end
73
- return code
74
- end
75
-
76
- def browse(level = 1, &block)
77
- code = ""
78
- value = (level == @levels ? 'value' : "h#{level}")
79
- code << "for l#{level}, #{value} in #{level == 1 ? '@root' : 'h'+(level-1).to_s}\n"
80
- if level > 1
81
- i = (level == @levels ? "index" : "i#{level}")
82
- code << " #{i} = ("+(level>2 ? "i" : "l")+"#{level-1} << #{@partition})|l#{level}\n"
83
- end
84
- if level == @levels
85
- code << yield.to_s.strip.gsub(/^/, ' ')+"\n"
86
- else
87
- code << browse(level + 1, &block).to_s.strip.gsub(/^/, ' ')+"\n"
88
- end
89
- code << "end\n"
90
- return code
91
- end
92
-
93
- def index_at_level(level, variable="index")
94
- v = variable
95
- v = "(#{v} >> #{(@levels-level)*@partition})" if level < @levels
96
- return "#{v}&#{2**@partition-1}"
97
- end
98
-
99
-
100
- end