calco 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +360 -0
- data/Rakefile +1 -0
- data/calco.gemspec +23 -0
- data/examples/ages.ods +0 -0
- data/examples/compute_cells.rb +61 -0
- data/examples/data.csv +8 -0
- data/examples/example.rb +97 -0
- data/examples/multiplication_tables.ods +0 -0
- data/examples/multiplication_tables.rb +73 -0
- data/examples/register_function.rb +44 -0
- data/examples/using_date_functions.rb +42 -0
- data/examples/write_csv.rb +68 -0
- data/examples/write_ods.rb +69 -0
- data/lib/calco.rb +17 -0
- data/lib/calco/core_ext/fixnum.rb +22 -0
- data/lib/calco/core_ext/float.rb +22 -0
- data/lib/calco/core_ext/range.rb +15 -0
- data/lib/calco/core_ext/string.rb +20 -0
- data/lib/calco/date_functions.rb +13 -0
- data/lib/calco/definition_dsl.rb +127 -0
- data/lib/calco/elements/aggregator.rb +17 -0
- data/lib/calco/elements/builtin_function.rb +84 -0
- data/lib/calco/elements/constant.rb +31 -0
- data/lib/calco/elements/current.rb +19 -0
- data/lib/calco/elements/element.rb +31 -0
- data/lib/calco/elements/empty.rb +9 -0
- data/lib/calco/elements/formula.rb +42 -0
- data/lib/calco/elements/if.rb +26 -0
- data/lib/calco/elements/operation.rb +34 -0
- data/lib/calco/elements/operator.rb +17 -0
- data/lib/calco/elements/or.rb +26 -0
- data/lib/calco/elements/value_extractor.rb +42 -0
- data/lib/calco/elements/variable.rb +35 -0
- data/lib/calco/engines/calculator_builtin_functions.rb +32 -0
- data/lib/calco/engines/csv_engine.rb +80 -0
- data/lib/calco/engines/default_engine.rb +140 -0
- data/lib/calco/engines/office_engine.rb +263 -0
- data/lib/calco/engines/simple_calculator_engine.rb +151 -0
- data/lib/calco/math_functions.rb +9 -0
- data/lib/calco/sheet.rb +363 -0
- data/lib/calco/spreadsheet.rb +172 -0
- data/lib/calco/string_functions.rb +9 -0
- data/lib/calco/style.rb +15 -0
- data/lib/calco/time_functions.rb +12 -0
- data/lib/calco/version.rb +3 -0
- data/spec/absolute_references_spec.rb +86 -0
- data/spec/builtin_functions_spec.rb +161 -0
- data/spec/calculator_engine_spec.rb +251 -0
- data/spec/conditions_spec.rb +118 -0
- data/spec/content_change_spec.rb +190 -0
- data/spec/csv_engine_spec.rb +324 -0
- data/spec/default_engine_spec.rb +135 -0
- data/spec/definitions_spec.rb +65 -0
- data/spec/errors_spec.rb +189 -0
- data/spec/functions_spec.rb +251 -0
- data/spec/header_row_spec.rb +63 -0
- data/spec/range_spec.rb +189 -0
- data/spec/sheet_selections_spec.rb +49 -0
- data/spec/sheet_spec.rb +229 -0
- data/spec/smart_types_spec.rb +43 -0
- data/spec/spreadsheet_spec.rb +80 -0
- data/spec/styles_spec.rb +29 -0
- data/spec/variables_spec.rb +41 -0
- metadata +158 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'calco'
|
2
|
+
|
3
|
+
describe "Implicit type conversion" do
|
4
|
+
|
5
|
+
it "detects time values" do
|
6
|
+
|
7
|
+
doc = spreadsheet do
|
8
|
+
|
9
|
+
definitions do
|
10
|
+
|
11
|
+
set time: '8:11'
|
12
|
+
set not_time: '13,01'
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(doc.current[:time]).to be_a(Time)
|
19
|
+
expect(doc.current[:not_time]).to be_a(String)
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it "detects date values" do
|
24
|
+
|
25
|
+
doc = spreadsheet do
|
26
|
+
|
27
|
+
definitions do
|
28
|
+
|
29
|
+
set date1: '2013-06-17'
|
30
|
+
set date2: '2013/06/17'
|
31
|
+
set not_date: '2013 06 17'
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(doc.current[:date1]).to be_a(Date)
|
38
|
+
expect(doc.current[:date2]).to be_a(Date)
|
39
|
+
expect(doc.current[:not_date]).to be_a(String)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'calco'
|
2
|
+
require 'calco/engines/csv_engine'
|
3
|
+
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.alias_example_to :the
|
6
|
+
end
|
7
|
+
|
8
|
+
module Calco
|
9
|
+
|
10
|
+
describe Spreadsheet do
|
11
|
+
|
12
|
+
the 'Spreadsheet#row method returns value of current Sheet#row' do
|
13
|
+
|
14
|
+
doc = create_sheet
|
15
|
+
|
16
|
+
doc.sheet("sheet 1")
|
17
|
+
|
18
|
+
expect(doc.row_to_hash(7)).to eq({
|
19
|
+
'A' => '25',
|
20
|
+
'B' => "2013-09-21",
|
21
|
+
'C' => 'A7*7'
|
22
|
+
})
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
the 'Spreadsheet#engine= method changes the engine' do
|
27
|
+
|
28
|
+
doc = create_sheet
|
29
|
+
|
30
|
+
doc.sheet("sheet 2")
|
31
|
+
|
32
|
+
expect(doc.row_to_hash(7)).to eq({
|
33
|
+
'A' => "2013-09-21",
|
34
|
+
'B' => '2013-09-21; apply_style(IF(self=TODAY();"red";"default"))'
|
35
|
+
})
|
36
|
+
|
37
|
+
doc.engine = Calco::CSVEngine.new
|
38
|
+
|
39
|
+
expect(doc.row_to_hash(7)).to eq({
|
40
|
+
'A' => '=DATEVALUE("2013-09-21")',
|
41
|
+
'B' => '=DATEVALUE("2013-09-21")+STYLE(IF(CURRENT()=TODAY();"red";"default"))'
|
42
|
+
})
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_sheet
|
47
|
+
|
48
|
+
spreadsheet do
|
49
|
+
|
50
|
+
definitions do
|
51
|
+
|
52
|
+
set value: 25
|
53
|
+
set some_date: "2013-09-21"
|
54
|
+
|
55
|
+
function times_7: value * 7
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
sheet "sheet 1" do
|
60
|
+
|
61
|
+
column value_of(:value)
|
62
|
+
column value_of(:some_date)
|
63
|
+
column :times_7
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
sheet "sheet 2" do
|
68
|
+
|
69
|
+
column value_of(:some_date)
|
70
|
+
column value_of(:some_date), style: _if(current == today(), 'red', 'default')
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/spec/styles_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'calco'
|
2
|
+
|
3
|
+
describe "Spreadsheet's sheet" do
|
4
|
+
|
5
|
+
it "supports dynamic styles" do
|
6
|
+
|
7
|
+
doc = spreadsheet do
|
8
|
+
|
9
|
+
definitions do
|
10
|
+
|
11
|
+
set price: 14.4
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
sheet do
|
16
|
+
|
17
|
+
column value_of(:price), style: _if(current > 120, 'Alert', 'default')
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
row = doc.row(1)
|
24
|
+
|
25
|
+
expect(row[0]).to eq('14.4; apply_style(IF(self>120;"Alert";"default"))')
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'calco'
|
2
|
+
|
3
|
+
RSpec.configure do |c|
|
4
|
+
c.alias_example_to :we_can
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "With variables we can" do
|
8
|
+
|
9
|
+
we_can "assign a value to a variable name" do
|
10
|
+
|
11
|
+
doc = spreadsheet do
|
12
|
+
|
13
|
+
definitions do
|
14
|
+
set name: 'John'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(doc.current[:name]).to eq('John')
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
we_can "change the value of a variable" do
|
24
|
+
|
25
|
+
doc = spreadsheet do
|
26
|
+
|
27
|
+
definitions do
|
28
|
+
set name: 'John'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
sheet = doc.current
|
34
|
+
|
35
|
+
sheet[:name] = 99
|
36
|
+
|
37
|
+
expect(sheet[:name]).to eq(99)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: calco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean Lazarou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubyzip
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.0
|
41
|
+
description: Implements a DSL used to create and define the content of spreadsheet
|
42
|
+
documents
|
43
|
+
email:
|
44
|
+
- jean.lazarou@alef1.org
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- calco.gemspec
|
57
|
+
- examples/ages.ods
|
58
|
+
- examples/compute_cells.rb
|
59
|
+
- examples/data.csv
|
60
|
+
- examples/example.rb
|
61
|
+
- examples/multiplication_tables.ods
|
62
|
+
- examples/multiplication_tables.rb
|
63
|
+
- examples/register_function.rb
|
64
|
+
- examples/using_date_functions.rb
|
65
|
+
- examples/write_csv.rb
|
66
|
+
- examples/write_ods.rb
|
67
|
+
- lib/calco.rb
|
68
|
+
- lib/calco/core_ext/fixnum.rb
|
69
|
+
- lib/calco/core_ext/float.rb
|
70
|
+
- lib/calco/core_ext/range.rb
|
71
|
+
- lib/calco/core_ext/string.rb
|
72
|
+
- lib/calco/date_functions.rb
|
73
|
+
- lib/calco/definition_dsl.rb
|
74
|
+
- lib/calco/elements/aggregator.rb
|
75
|
+
- lib/calco/elements/builtin_function.rb
|
76
|
+
- lib/calco/elements/constant.rb
|
77
|
+
- lib/calco/elements/current.rb
|
78
|
+
- lib/calco/elements/element.rb
|
79
|
+
- lib/calco/elements/empty.rb
|
80
|
+
- lib/calco/elements/formula.rb
|
81
|
+
- lib/calco/elements/if.rb
|
82
|
+
- lib/calco/elements/operation.rb
|
83
|
+
- lib/calco/elements/operator.rb
|
84
|
+
- lib/calco/elements/or.rb
|
85
|
+
- lib/calco/elements/value_extractor.rb
|
86
|
+
- lib/calco/elements/variable.rb
|
87
|
+
- lib/calco/engines/calculator_builtin_functions.rb
|
88
|
+
- lib/calco/engines/csv_engine.rb
|
89
|
+
- lib/calco/engines/default_engine.rb
|
90
|
+
- lib/calco/engines/office_engine.rb
|
91
|
+
- lib/calco/engines/simple_calculator_engine.rb
|
92
|
+
- lib/calco/math_functions.rb
|
93
|
+
- lib/calco/sheet.rb
|
94
|
+
- lib/calco/spreadsheet.rb
|
95
|
+
- lib/calco/string_functions.rb
|
96
|
+
- lib/calco/style.rb
|
97
|
+
- lib/calco/time_functions.rb
|
98
|
+
- lib/calco/version.rb
|
99
|
+
- spec/absolute_references_spec.rb
|
100
|
+
- spec/builtin_functions_spec.rb
|
101
|
+
- spec/calculator_engine_spec.rb
|
102
|
+
- spec/conditions_spec.rb
|
103
|
+
- spec/content_change_spec.rb
|
104
|
+
- spec/csv_engine_spec.rb
|
105
|
+
- spec/default_engine_spec.rb
|
106
|
+
- spec/definitions_spec.rb
|
107
|
+
- spec/errors_spec.rb
|
108
|
+
- spec/functions_spec.rb
|
109
|
+
- spec/header_row_spec.rb
|
110
|
+
- spec/range_spec.rb
|
111
|
+
- spec/sheet_selections_spec.rb
|
112
|
+
- spec/sheet_spec.rb
|
113
|
+
- spec/smart_types_spec.rb
|
114
|
+
- spec/spreadsheet_spec.rb
|
115
|
+
- spec/styles_spec.rb
|
116
|
+
- spec/variables_spec.rb
|
117
|
+
homepage: https://github.com/jeanlazarou/calco
|
118
|
+
licenses: []
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.2.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: DSL for spreadsheet documents
|
140
|
+
test_files:
|
141
|
+
- spec/absolute_references_spec.rb
|
142
|
+
- spec/builtin_functions_spec.rb
|
143
|
+
- spec/calculator_engine_spec.rb
|
144
|
+
- spec/conditions_spec.rb
|
145
|
+
- spec/content_change_spec.rb
|
146
|
+
- spec/csv_engine_spec.rb
|
147
|
+
- spec/default_engine_spec.rb
|
148
|
+
- spec/definitions_spec.rb
|
149
|
+
- spec/errors_spec.rb
|
150
|
+
- spec/functions_spec.rb
|
151
|
+
- spec/header_row_spec.rb
|
152
|
+
- spec/range_spec.rb
|
153
|
+
- spec/sheet_selections_spec.rb
|
154
|
+
- spec/sheet_spec.rb
|
155
|
+
- spec/smart_types_spec.rb
|
156
|
+
- spec/spreadsheet_spec.rb
|
157
|
+
- spec/styles_spec.rb
|
158
|
+
- spec/variables_spec.rb
|