osheet-xmlss 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.log
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ .rvmrc
8
+ .rbenv-version
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in osheet-xmlss.gemspec
4
+ gemspec
5
+
6
+ gem 'bundler', '~>1.1'
7
+ gem 'rake', '~>0.9.2'
8
+ gem "whysoslow", "~> 0.0"
9
+ gem "ruby-prof"
data/LICENSE 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,131 @@
1
+ # Osheet::Xmlss
2
+
3
+ A writer for Osheet (https://github.com/kellyredding/osheet). Use this with Osheet to write workbooks in the Xmlss format (https://github.com/kellyredding/xmlss.)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'osheet-xmlss'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install osheet-xmlss
18
+
19
+ Osheet::Xmlss will install Osheet and Xmlss for you and you are all set.
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'osheet/xmlss'
25
+
26
+ fields = ['Sex', 'Age', 'Height', 'Weight']
27
+ data = {
28
+ 'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
29
+ 'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
30
+ 'Sally' => ['F', 29, "5'3\"", '132 lbs.']
31
+ }
32
+
33
+ # this will dump the above data to a single-sheet workbook w/ no styles
34
+ # - this example is using the Xmlss writer (https://github.com/kellyredding/xmlss)
35
+
36
+ Osheet::Workbook.new(Osheet::XmlssWriter.new) {
37
+ title "basic"
38
+
39
+ template(:column, :data) { |field, index|
40
+ width 80
41
+ meta(
42
+ :label => field.to_s,
43
+ :index => index
44
+ )
45
+ }
46
+
47
+ template(:row, :title) {
48
+ cell {
49
+ colspan columns.count
50
+ data worksheet.name
51
+ }
52
+ }
53
+
54
+ template(:row, :empty) {
55
+ cell {
56
+ colspan columns.count
57
+ data ''
58
+ }
59
+ }
60
+
61
+ template(:row, :header) {
62
+ columns.each do |column|
63
+ cell {
64
+ data column.meta[:label]
65
+ }
66
+ end
67
+ }
68
+
69
+ template(:row, :data) { |name, stats|
70
+ cell {
71
+ data name
72
+ }
73
+ stats.each do |stat|
74
+ cell {
75
+ data stat
76
+ }
77
+ end
78
+ }
79
+
80
+ worksheet {
81
+ name "Stats: #{fields.join(', ')}"
82
+
83
+ column {
84
+ width 200
85
+ meta(
86
+ :label => "Name"
87
+ )
88
+ }
89
+ fields.each_with_index do |f, i|
90
+ column :data, f, i
91
+ end
92
+
93
+ row :title
94
+ row :empty
95
+ row :header
96
+
97
+ data.each do |name, stats|
98
+ row :data, name, stats
99
+ end
100
+ }
101
+ }.to_file('stats.xls')
102
+ ```
103
+
104
+ ## Writer Options
105
+
106
+ * `:pp`: (pretty-print) set to a Fixnum to tab-space indent pretty print the output (from Undies, https://github.com/kellyredding/undies)
107
+
108
+ ## API
109
+
110
+ Check out the Osheet wiki: https://github.com/kelredd/osheet/wiki. It covers the full Osheet API.
111
+
112
+ ## Examples
113
+
114
+ I've add 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.
115
+
116
+ ## Links
117
+
118
+ * *Osheet Wiki*
119
+ - https://github.com/kellyredding/osheet/wiki
120
+ * *Osheet Source*
121
+ - http://github.com/kellyredding/osheet
122
+ * *Xmlss Source*
123
+ - http://github.com/kellyredding/xmlss
124
+
125
+ ## Contributing
126
+
127
+ 1. Fork it
128
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
129
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
130
+ 4. Push to the branch (`git push origin my-new-feature`)
131
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'assert/rake_tasks'
4
+ Assert::RakeTasks.for(:test)
5
+
6
+ require 'bundler/gem_tasks'
7
+
8
+ task :default => :build
9
+
10
+ namespace :bench do
11
+
12
+ desc "Run the bench script."
13
+ task :run do
14
+ require 'bench/bench_runner'
15
+ OsheetXmlssBenchRunner.new
16
+ end
17
+
18
+ desc "Run the profiler on 1000 rows."
19
+ task :profiler do
20
+ require 'bench/profiler_runner'
21
+ runner = OsheetXmlssProfilerRunner.new(1000)
22
+ runner.print_flat(STDOUT, :min_percent => 3)
23
+ end
24
+
25
+ desc "Run the example workbook builds."
26
+ task :examples do
27
+ require 'examples/trivial'
28
+ require 'examples/basic'
29
+ require 'examples/basic_with_templates'
30
+ require 'examples/formats'
31
+ require 'examples/formula'
32
+ require 'examples/styles'
33
+ end
34
+
35
+ desc "Run all the tests, then the example builds, then the profiler."
36
+ task :all do
37
+ Rake::Task['test'].invoke
38
+ Rake::Task['bench:run'].invoke
39
+ Rake::Task['bench:profiler'].invoke
40
+ Rake::Task['bench:examples'].invoke
41
+ end
42
+
43
+
44
+ end
45
+
46
+ task :bench do
47
+ Rake::Task['bench:run'].invoke
48
+ end
49
+
@@ -0,0 +1,91 @@
1
+ require 'whysoslow'
2
+ require 'stringio'
3
+
4
+ require 'osheet/xmlss'
5
+
6
+ class OsheetXmlssBenchResults
7
+
8
+ def initialize(row_count)
9
+ @row_count = row_count
10
+ @printer = Whysoslow::DefaultPrinter.new({
11
+ :title => "#{@row_count} rows",
12
+ :verbose => true
13
+ })
14
+ @runner = Whysoslow::Runner.new(@printer)
15
+ end
16
+
17
+ def run
18
+ @runner.run do
19
+ data_values = {
20
+ :number => 1,
21
+ :text => 'text',
22
+ :currency => 123.45,
23
+ :text => "<>&'\"/",
24
+ :currency => 45.23
25
+ }
26
+
27
+ outstream = StringIO.new(out = "")
28
+ outstream << Osheet::Workbook.new(Osheet::XmlssWriter.new(:pp => 2), {
29
+ :bench_row_count => @row_count,
30
+ :runner => @runner
31
+ }) {
32
+ title "bench"
33
+
34
+ template(:row, :header) {
35
+ columns.each do |column|
36
+ cell {
37
+ data column.meta[:label]
38
+ }
39
+ end
40
+ }
41
+
42
+ template(:row, :data) { |values|
43
+ columns.each do |col|
44
+ cell {
45
+ data values[col.meta[:label]]
46
+ format col.meta[:label]
47
+ }
48
+ end
49
+ }
50
+
51
+ worksheet {
52
+ name "bench results"
53
+
54
+ data_values.keys.each do |label|
55
+ column {
56
+ width 200
57
+ meta(:label => label)
58
+ }
59
+ end
60
+
61
+ row :header
62
+
63
+ 10.times do |i|
64
+ (bench_row_count / 10).times do
65
+ row :data, data_values
66
+ end
67
+ runner.snapshot("#{((i+1)*10).to_s.rjust(3)}%")
68
+ end
69
+ }
70
+ }.to_data
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ class OsheetXmlssBenchRunner
77
+
78
+ ROWS = [10, 100, 1000]#, 10000]#, 30000]
79
+
80
+ def initialize
81
+ puts "Benchmark Results:"
82
+ puts
83
+ ROWS.each do |size|
84
+ OsheetXmlssBenchResults.new(size).run
85
+ puts
86
+ end
87
+ puts
88
+ end
89
+
90
+ end
91
+
data/bench/profiler.rb ADDED
@@ -0,0 +1,6 @@
1
+ # $ bundle exec ruby bench/profiler.rb
2
+
3
+ require 'bench/profiler_runner'
4
+
5
+ runner = OsheetXmlssProfilerRunner.new(ARGV[0] ? ARGV[0].to_i : 1000)
6
+ runner.print_flat(STDOUT, :min_percent => 1)