osheet 1.0.0.rc.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +17 -6
  2. data/Gemfile +3 -4
  3. data/LICENSE.txt +22 -0
  4. data/README.md +129 -0
  5. data/Rakefile +1 -7
  6. data/lib/osheet/cell.rb +0 -1
  7. data/lib/osheet/column.rb +3 -2
  8. data/lib/osheet/format.rb +9 -9
  9. data/lib/osheet/format/accounting.rb +0 -1
  10. data/lib/osheet/format/currency.rb +1 -1
  11. data/lib/osheet/format/custom.rb +0 -1
  12. data/lib/osheet/format/datetime.rb +0 -1
  13. data/lib/osheet/format/fraction.rb +0 -1
  14. data/lib/osheet/format/general.rb +2 -2
  15. data/lib/osheet/format/number.rb +0 -1
  16. data/lib/osheet/format/numeric.rb +2 -1
  17. data/lib/osheet/format/percentage.rb +2 -1
  18. data/lib/osheet/format/scientific.rb +2 -1
  19. data/lib/osheet/format/special.rb +0 -1
  20. data/lib/osheet/format/text.rb +0 -1
  21. data/lib/osheet/mixin.rb +1 -0
  22. data/lib/osheet/row.rb +0 -1
  23. data/lib/osheet/style.rb +1 -0
  24. data/lib/osheet/styled_element.rb +1 -0
  25. data/lib/osheet/version.rb +1 -1
  26. data/lib/osheet/workbook.rb +0 -4
  27. data/lib/osheet/workbook_element.rb +0 -10
  28. data/osheet.gemspec +18 -16
  29. data/test/helper.rb +6 -2
  30. data/test/{fixtures → support}/mixins.rb +0 -0
  31. data/test/{fixtures → support}/test_writer.rb +0 -0
  32. data/test/{cell_test.rb → unit/cell_tests.rb} +15 -12
  33. data/test/{column_test.rb → unit/column_tests.rb} +10 -9
  34. data/test/{format/accounting_test.rb → unit/format/accounting_tests.rb} +35 -26
  35. data/test/{format/currency_test.rb → unit/format/currency_tests.rb} +35 -26
  36. data/test/{format/custom_test.rb → unit/format/custom_tests.rb} +6 -5
  37. data/test/{format/datetime_test.rb → unit/format/datetime_tests.rb} +6 -5
  38. data/test/{format/fraction_test.rb → unit/format/fraction_tests.rb} +16 -16
  39. data/test/{format/general_test.rb → unit/format/general_tests.rb} +5 -5
  40. data/test/unit/format/number_tests.rb +96 -0
  41. data/test/{format/percentage_test.rb → unit/format/percentage_tests.rb} +32 -23
  42. data/test/{format/scientific_test.rb → unit/format/scientific_tests.rb} +31 -23
  43. data/test/{format/special_test.rb → unit/format/special_tests.rb} +11 -11
  44. data/test/{format/text_test.rb → unit/format/text_tests.rb} +4 -4
  45. data/test/{format_test.rb → unit/format_tests.rb} +8 -7
  46. data/test/{mixin_test.rb → unit/mixin_tests.rb} +11 -10
  47. data/test/{partial_test.rb → unit/partial_tests.rb} +13 -10
  48. data/test/{row_test.rb → unit/row_tests.rb} +11 -10
  49. data/test/{style_test.rb → unit/style_tests.rb} +13 -14
  50. data/test/{template_test.rb → unit/template_tests.rb} +15 -12
  51. data/test/{workbook_element_test.rb → unit/workbook_element_tests.rb} +48 -54
  52. data/test/{workbook_test.rb → unit/workbook_tests.rb} +34 -30
  53. data/test/{worksheet_test.rb → unit/worksheet_tests.rb} +13 -13
  54. metadata +70 -76
  55. data/Gemfile.lock +0 -27
  56. data/README.rdoc +0 -133
  57. data/test/format/number_test.rb +0 -91
  58. data/test/irb.rb +0 -9
data/.gitignore CHANGED
@@ -1,8 +1,19 @@
1
- pkg/*
2
- .bundle
3
1
  *.gem
4
2
  *.log
5
- .rvmrc
6
- .rbenv-version
7
- /tmp
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
@@ -1,7 +1,6 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in osheet.gemspec
4
3
  gemspec
5
4
 
6
- gem 'bundler', '~>1.1'
7
- gem 'rake', '~>0.9.2'
5
+ gem 'rake'
6
+ gem 'pry'
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
@@ -1,7 +1 @@
1
- require 'assert/rake_tasks'
2
- include Assert::RakeTasks
3
-
4
- require 'bundler'
5
- Bundler::GemHelper.install_tasks
6
-
7
- task :default => :build
1
+ require "bundler/gem_tasks"
data/lib/osheet/cell.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'date'
2
-
3
2
  require 'osheet/format'
4
3
  require 'osheet/meta_element'
5
4
  require 'osheet/styled_element'
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 = width
14
+ @width = width
14
15
  @autofit = false
15
- @hidden = false
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::Format
13
+ module Osheet
14
+ module Format
14
15
 
15
- VALUES = [
16
- :general, :number, :currency, :accounting,
17
- :datetime, :percentage, :fraction, :scientific,
18
- :text, :special, :custom
19
- ]
16
+ VALUES = [
17
+ :general, :number, :currency, :accounting,
18
+ :datetime, :percentage, :fraction, :scientific,
19
+ :text, :special, :custom
20
+ ]
20
21
 
21
- class << self
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
@@ -2,7 +2,6 @@ require 'enumeration'
2
2
  require 'osheet/format/currency'
3
3
 
4
4
  module Osheet::Format
5
-
6
5
  class Accounting < Osheet::Format::Currency
7
6
 
8
7
  protected
@@ -2,8 +2,8 @@ require 'enumeration'
2
2
  require 'osheet/format/numeric'
3
3
 
4
4
  module Osheet::Format
5
-
6
5
  class Currency < Osheet::Format::Numeric
6
+
7
7
  def initialize(opts={})
8
8
  super({
9
9
  :symbol => 'dollar',
@@ -1,5 +1,4 @@
1
1
  module Osheet::Format
2
-
3
2
  class Custom
4
3
 
5
4
  def initialize(type)
@@ -1,5 +1,4 @@
1
1
  module Osheet::Format
2
-
3
2
  class Datetime
4
3
 
5
4
  def initialize(string)
@@ -1,7 +1,6 @@
1
1
  require 'enumeration'
2
2
 
3
3
  module Osheet::Format
4
-
5
4
  class Fraction
6
5
  include Enumeration
7
6
 
@@ -1,9 +1,9 @@
1
1
  module Osheet::Format
2
-
3
2
  class General
3
+
4
4
  def initialize(opts={}); end
5
5
  def style; nil; end
6
6
  def key; ''; end
7
- end
8
7
 
8
+ end
9
9
  end
@@ -2,7 +2,6 @@ require 'enumeration'
2
2
  require 'osheet/format/numeric'
3
3
 
4
4
  module Osheet::Format
5
-
6
5
  class Number < Osheet::Format::Numeric
7
6
 
8
7
  def initialize(opts={})
@@ -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
@@ -1,7 +1,6 @@
1
1
  require 'enumeration'
2
2
 
3
3
  module Osheet::Format
4
-
5
4
  class Special
6
5
  include Enumeration
7
6
 
@@ -1,5 +1,4 @@
1
1
  module Osheet::Format
2
-
3
2
  class Text
4
3
 
5
4
  def initialize(opts={}); end
data/lib/osheet/mixin.rb CHANGED
@@ -46,6 +46,7 @@ module Osheet::Mixin
46
46
  def partials
47
47
  instance_variable_get("@p") || []
48
48
  end
49
+
49
50
  end
50
51
 
51
52
  end
data/lib/osheet/row.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'osheet/meta_element'
2
2
  require 'osheet/styled_element'
3
-
4
3
  require 'osheet/cell'
5
4
 
6
5
  module Osheet
data/lib/osheet/style.rb CHANGED
@@ -53,5 +53,6 @@ module Osheet
53
53
  selector =~ /^[^.]/ ||
54
54
  selector =~ />+/
55
55
  end
56
+
56
57
  end
57
58
  end
@@ -23,4 +23,5 @@ module Osheet::StyledElement
23
23
  style_class =~ /\.+/ ||
24
24
  style_class =~ />+/
25
25
  end
26
+
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module Osheet
2
- VERSION = "1.0.0.rc.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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