osheet 1.0.0.rc.4 → 1.0.0
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.
- data/.gitignore +17 -6
- data/Gemfile +3 -4
- data/LICENSE.txt +22 -0
- data/README.md +129 -0
- data/Rakefile +1 -7
- data/lib/osheet/cell.rb +0 -1
- data/lib/osheet/column.rb +3 -2
- data/lib/osheet/format.rb +9 -9
- data/lib/osheet/format/accounting.rb +0 -1
- data/lib/osheet/format/currency.rb +1 -1
- data/lib/osheet/format/custom.rb +0 -1
- data/lib/osheet/format/datetime.rb +0 -1
- data/lib/osheet/format/fraction.rb +0 -1
- data/lib/osheet/format/general.rb +2 -2
- data/lib/osheet/format/number.rb +0 -1
- data/lib/osheet/format/numeric.rb +2 -1
- data/lib/osheet/format/percentage.rb +2 -1
- data/lib/osheet/format/scientific.rb +2 -1
- data/lib/osheet/format/special.rb +0 -1
- data/lib/osheet/format/text.rb +0 -1
- data/lib/osheet/mixin.rb +1 -0
- data/lib/osheet/row.rb +0 -1
- data/lib/osheet/style.rb +1 -0
- data/lib/osheet/styled_element.rb +1 -0
- data/lib/osheet/version.rb +1 -1
- data/lib/osheet/workbook.rb +0 -4
- data/lib/osheet/workbook_element.rb +0 -10
- data/osheet.gemspec +18 -16
- data/test/helper.rb +6 -2
- data/test/{fixtures → support}/mixins.rb +0 -0
- data/test/{fixtures → support}/test_writer.rb +0 -0
- data/test/{cell_test.rb → unit/cell_tests.rb} +15 -12
- data/test/{column_test.rb → unit/column_tests.rb} +10 -9
- data/test/{format/accounting_test.rb → unit/format/accounting_tests.rb} +35 -26
- data/test/{format/currency_test.rb → unit/format/currency_tests.rb} +35 -26
- data/test/{format/custom_test.rb → unit/format/custom_tests.rb} +6 -5
- data/test/{format/datetime_test.rb → unit/format/datetime_tests.rb} +6 -5
- data/test/{format/fraction_test.rb → unit/format/fraction_tests.rb} +16 -16
- data/test/{format/general_test.rb → unit/format/general_tests.rb} +5 -5
- data/test/unit/format/number_tests.rb +96 -0
- data/test/{format/percentage_test.rb → unit/format/percentage_tests.rb} +32 -23
- data/test/{format/scientific_test.rb → unit/format/scientific_tests.rb} +31 -23
- data/test/{format/special_test.rb → unit/format/special_tests.rb} +11 -11
- data/test/{format/text_test.rb → unit/format/text_tests.rb} +4 -4
- data/test/{format_test.rb → unit/format_tests.rb} +8 -7
- data/test/{mixin_test.rb → unit/mixin_tests.rb} +11 -10
- data/test/{partial_test.rb → unit/partial_tests.rb} +13 -10
- data/test/{row_test.rb → unit/row_tests.rb} +11 -10
- data/test/{style_test.rb → unit/style_tests.rb} +13 -14
- data/test/{template_test.rb → unit/template_tests.rb} +15 -12
- data/test/{workbook_element_test.rb → unit/workbook_element_tests.rb} +48 -54
- data/test/{workbook_test.rb → unit/workbook_tests.rb} +34 -30
- data/test/{worksheet_test.rb → unit/worksheet_tests.rb} +13 -13
- metadata +70 -76
- data/Gemfile.lock +0 -27
- data/README.rdoc +0 -133
- data/test/format/number_test.rb +0 -91
- data/test/irb.rb +0 -9
data/.gitignore
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
-
pkg/*
|
2
|
-
.bundle
|
3
1
|
*.gem
|
4
2
|
*.log
|
5
|
-
|
6
|
-
.
|
7
|
-
|
8
|
-
|
3
|
+
*.rbc
|
4
|
+
.rbx/
|
5
|
+
.bundle
|
6
|
+
.config
|
7
|
+
.yardoc
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010-Present Kelly Redding
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Osheet
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
A DSL for specifying and generating spreadsheets using Ruby.
|
6
|
+
|
7
|
+
## Simple Usage Example
|
8
|
+
|
9
|
+
This example uses the Xmlss writer provided by Osheet::Xmlss (https://github.com/kellyredding/osheet-xmlss).
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'osheet'
|
13
|
+
require 'osheet/xmlss'
|
14
|
+
|
15
|
+
fields = ['Sex', 'Age', 'Height', 'Weight']
|
16
|
+
data = {
|
17
|
+
'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
|
18
|
+
'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
|
19
|
+
'Sally' => ['F', 29, "5'3\"", '132 lbs.']
|
20
|
+
}
|
21
|
+
|
22
|
+
# this will dump the above data to a single-sheet workbook w/ no styles
|
23
|
+
# - this example is using the Xmlss writer (https://github.com/kellyredding/xmlss)
|
24
|
+
|
25
|
+
Osheet::Workbook.new(Osheet::XmlssWriter.new) {
|
26
|
+
title "basic"
|
27
|
+
|
28
|
+
template(:column, :data) { |field, index|
|
29
|
+
width 80
|
30
|
+
meta(
|
31
|
+
:label => field.to_s,
|
32
|
+
:index => index
|
33
|
+
)
|
34
|
+
}
|
35
|
+
|
36
|
+
template(:row, :title) {
|
37
|
+
cell {
|
38
|
+
colspan columns.count
|
39
|
+
data worksheet.name
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
template(:row, :empty) {
|
44
|
+
cell {
|
45
|
+
colspan columns.count
|
46
|
+
data ''
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
template(:row, :header) {
|
51
|
+
columns.each do |column|
|
52
|
+
cell {
|
53
|
+
data column.meta[:label]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
template(:row, :data) { |name, stats|
|
59
|
+
cell {
|
60
|
+
data name
|
61
|
+
}
|
62
|
+
stats.each do |stat|
|
63
|
+
cell {
|
64
|
+
data stat
|
65
|
+
}
|
66
|
+
end
|
67
|
+
}
|
68
|
+
|
69
|
+
worksheet {
|
70
|
+
name "Stats: #{fields.join(', ')}"
|
71
|
+
|
72
|
+
column {
|
73
|
+
width 200
|
74
|
+
meta(
|
75
|
+
:label => "Name"
|
76
|
+
)
|
77
|
+
}
|
78
|
+
fields.each_with_index do |f, i|
|
79
|
+
column :data, f, i
|
80
|
+
end
|
81
|
+
|
82
|
+
row :title
|
83
|
+
row :empty
|
84
|
+
row :header
|
85
|
+
|
86
|
+
data.each do |name, stats|
|
87
|
+
row :data, name, stats
|
88
|
+
end
|
89
|
+
}
|
90
|
+
}.to_file('stats.xls')
|
91
|
+
```
|
92
|
+
|
93
|
+
## API
|
94
|
+
|
95
|
+
Check out the wiki: https://github.com/kelredd/osheet/wiki. It covers the full Osheet API.
|
96
|
+
|
97
|
+
## Examples
|
98
|
+
|
99
|
+
I've added a few examples to ./examples. Please refer first to the API then to these for examples on basic usage, using templates, formatting data, and styling data.
|
100
|
+
|
101
|
+
## Links
|
102
|
+
|
103
|
+
* *Osheet*
|
104
|
+
- http://github.com/kelredd/osheet
|
105
|
+
|
106
|
+
* *Wiki*
|
107
|
+
- https://github.com/kelredd/osheet/wiki
|
108
|
+
|
109
|
+
## Installation
|
110
|
+
|
111
|
+
Add this line to your application's Gemfile:
|
112
|
+
|
113
|
+
gem 'whysoslow'
|
114
|
+
|
115
|
+
And then execute:
|
116
|
+
|
117
|
+
$ bundle
|
118
|
+
|
119
|
+
Or install it yourself as:
|
120
|
+
|
121
|
+
$ gem install whysoslow
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
1. Fork it
|
126
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
127
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
128
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
129
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/lib/osheet/cell.rb
CHANGED
data/lib/osheet/column.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'osheet/meta_element'
|
2
2
|
require 'osheet/styled_element'
|
3
|
+
require 'osheet/format'
|
3
4
|
|
4
5
|
module Osheet
|
5
6
|
class Column
|
@@ -10,9 +11,9 @@ module Osheet
|
|
10
11
|
attr_reader :format
|
11
12
|
|
12
13
|
def initialize(width=nil)
|
13
|
-
@width
|
14
|
+
@width = width
|
14
15
|
@autofit = false
|
15
|
-
@hidden
|
16
|
+
@hidden = false
|
16
17
|
@format = Format.new(:general)
|
17
18
|
end
|
18
19
|
|
data/lib/osheet/format.rb
CHANGED
@@ -10,21 +10,21 @@ require 'osheet/format/text'
|
|
10
10
|
require 'osheet/format/special'
|
11
11
|
require 'osheet/format/custom'
|
12
12
|
|
13
|
-
module Osheet
|
13
|
+
module Osheet
|
14
|
+
module Format
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
VALUES = [
|
17
|
+
:general, :number, :currency, :accounting,
|
18
|
+
:datetime, :percentage, :fraction, :scientific,
|
19
|
+
:text, :special, :custom
|
20
|
+
]
|
20
21
|
|
21
|
-
|
22
|
-
def new(type, *args)
|
22
|
+
def self.new(type, *args)
|
23
23
|
unless VALUES.include?(type.to_sym)
|
24
24
|
raise ArgumentError, "'#{type.inspect}' is not a valid format type"
|
25
25
|
end
|
26
26
|
self.const_get(type.to_s.capitalize).new(*args)
|
27
27
|
end
|
28
|
-
end
|
29
28
|
|
29
|
+
end
|
30
30
|
end
|
data/lib/osheet/format/custom.rb
CHANGED
data/lib/osheet/format/number.rb
CHANGED
@@ -3,16 +3,17 @@
|
|
3
3
|
require 'enumeration'
|
4
4
|
|
5
5
|
module Osheet::Format
|
6
|
-
|
7
6
|
class Numeric
|
8
7
|
include Enumeration
|
9
8
|
|
10
9
|
attr_accessor :decimal_places, :comma_separator
|
10
|
+
|
11
11
|
enum :symbol, {
|
12
12
|
:none => "none",
|
13
13
|
:dollar => "dollar",
|
14
14
|
:euro => "euro"
|
15
15
|
}
|
16
|
+
|
16
17
|
enum :negative_numbers, {
|
17
18
|
:black => "black",
|
18
19
|
:black_parenth => "black_parenth",
|
@@ -2,8 +2,8 @@ require 'enumeration'
|
|
2
2
|
require 'osheet/format/numeric'
|
3
3
|
|
4
4
|
module Osheet::Format
|
5
|
-
|
6
5
|
class Percentage < Osheet::Format::Numeric
|
6
|
+
|
7
7
|
def initialize(opts={})
|
8
8
|
super({
|
9
9
|
:decimal_places => 2
|
@@ -21,5 +21,6 @@ module Osheet::Format
|
|
21
21
|
def decimal_places_suffix
|
22
22
|
"%"
|
23
23
|
end
|
24
|
+
|
24
25
|
end
|
25
26
|
end
|
@@ -2,8 +2,8 @@ require 'enumeration'
|
|
2
2
|
require 'osheet/format/numeric'
|
3
3
|
|
4
4
|
module Osheet::Format
|
5
|
-
|
6
5
|
class Scientific < Osheet::Format::Numeric
|
6
|
+
|
7
7
|
def initialize(opts={})
|
8
8
|
super({
|
9
9
|
:decimal_places => 2
|
@@ -21,5 +21,6 @@ module Osheet::Format
|
|
21
21
|
def decimal_places_suffix
|
22
22
|
"E+00"
|
23
23
|
end
|
24
|
+
|
24
25
|
end
|
25
26
|
end
|
data/lib/osheet/format/text.rb
CHANGED
data/lib/osheet/mixin.rb
CHANGED
data/lib/osheet/row.rb
CHANGED
data/lib/osheet/style.rb
CHANGED
data/lib/osheet/version.rb
CHANGED
data/lib/osheet/workbook.rb
CHANGED
@@ -5,7 +5,6 @@ require 'osheet/workbook_api'
|
|
5
5
|
|
6
6
|
module Osheet
|
7
7
|
|
8
|
-
|
9
8
|
class Workbook
|
10
9
|
|
11
10
|
# This 'Workbook' class is really just a scope for workbook builds to run
|
@@ -96,8 +95,6 @@ module Osheet
|
|
96
95
|
|
97
96
|
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
98
|
class Workbook::ElementStack
|
102
99
|
|
103
100
|
# this class is just a wrapper to Array. I want to treat this as a
|
@@ -133,5 +130,4 @@ module Osheet
|
|
133
130
|
|
134
131
|
end
|
135
132
|
|
136
|
-
|
137
133
|
end
|