osheet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +110 -0
- data/Rakefile +58 -0
- data/lib/osheet/base.rb +95 -0
- data/lib/osheet/cell.rb +18 -0
- data/lib/osheet/column.rb +11 -0
- data/lib/osheet/row.rb +14 -0
- data/lib/osheet/version.rb +13 -0
- data/lib/osheet/workbook.rb +23 -0
- data/lib/osheet/worksheet.rb +29 -0
- data/lib/osheet.rb +32 -0
- metadata +113 -0
data/README.rdoc
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
= Osheet
|
2
|
+
* Osheet is under development and should not be relied upon just yet. Thx. *
|
3
|
+
|
4
|
+
== Description
|
5
|
+
|
6
|
+
Pronounced 'oh-sheeeeeet!' - this gem is a DSL wrapper to the spreadsheet gem that hopefully doesn't totally suck.
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
$ gem install osheet
|
11
|
+
|
12
|
+
== Basic Usage
|
13
|
+
|
14
|
+
require 'osheet'
|
15
|
+
|
16
|
+
Osheet::Workbook do |wb|
|
17
|
+
wb.worksheet "Users" do |sheet|
|
18
|
+
sheet.column
|
19
|
+
sheet.column
|
20
|
+
sheet.column
|
21
|
+
|
22
|
+
sheet.row do |r|
|
23
|
+
r.cell "Characters on \"Friends\"", :colspan => 3
|
24
|
+
end
|
25
|
+
sheet.row do |r|
|
26
|
+
r.cell "man, that show was awesome...", :colspan => 3
|
27
|
+
end
|
28
|
+
|
29
|
+
sheet.row do |r|
|
30
|
+
r.cell "", :colspan => 1
|
31
|
+
r.cell 'only concern yourself with these columns', :colspan => 2
|
32
|
+
end
|
33
|
+
|
34
|
+
sheet.row do |r|
|
35
|
+
r.cell "id"
|
36
|
+
r.cell "name"
|
37
|
+
r.cell "description"
|
38
|
+
end
|
39
|
+
|
40
|
+
sheet.row do |r|
|
41
|
+
r.cell 1
|
42
|
+
r.cell "Ross"
|
43
|
+
r.cell "the nerdy one, brother of Monica, dated Rachel, likes impregnating women, loves Rachel"
|
44
|
+
end
|
45
|
+
|
46
|
+
sheet.row do |r|
|
47
|
+
r.cell 2
|
48
|
+
r.cell "Rachel"
|
49
|
+
r.cell "the hot one, dated and impregnated by Ross, generally spoiled"
|
50
|
+
end
|
51
|
+
|
52
|
+
sheet.row do |r|
|
53
|
+
r.cell 3
|
54
|
+
r.cell "Chandler"
|
55
|
+
r.cell "the responsible one, husband of Monica, insecure about everything"
|
56
|
+
end
|
57
|
+
|
58
|
+
sheet.row do |r|
|
59
|
+
r.cell 4
|
60
|
+
r.cell "Monica"
|
61
|
+
r.cell "the smart one, wife of Chandler, sister of Ross, OCD about cleaning and controlling"
|
62
|
+
end
|
63
|
+
|
64
|
+
sheet.row do |r|
|
65
|
+
r.cell 5
|
66
|
+
r.cell "Joey"
|
67
|
+
r.cell "the man-whore one, best-friend of Chandler, generally dumb, can't sustain sitcom on own"
|
68
|
+
end
|
69
|
+
|
70
|
+
sheet.row do |r|
|
71
|
+
r.cell 6
|
72
|
+
r.cell "Phoebe"
|
73
|
+
r.cell "the crazy one, ex-roomate of Rachel, blond, free, weird, yet awesome"
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
== Links
|
80
|
+
|
81
|
+
* *GitHub*
|
82
|
+
- http://github.com/kelredd/osheet
|
83
|
+
|
84
|
+
* *Spreadsheet*
|
85
|
+
- http://spreadsheet.rubyforge.org/
|
86
|
+
|
87
|
+
== License
|
88
|
+
|
89
|
+
Copyright (c) 2010 and beyond, Kelly Redding (mailto:kelly@kelredd.com)
|
90
|
+
|
91
|
+
Permission is hereby granted, free of charge, to any person
|
92
|
+
obtaining a copy of this software and associated documentation
|
93
|
+
files (the "Software"), to deal in the Software without
|
94
|
+
restriction, including without limitation the rights to use,
|
95
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
96
|
+
copies of the Software, and to permit persons to whom the
|
97
|
+
Software is furnished to do so, subject to the following
|
98
|
+
conditions:
|
99
|
+
|
100
|
+
The above copyright notice and this permission notice shall be
|
101
|
+
included in all copies or substantial portions of the Software.
|
102
|
+
|
103
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
104
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
105
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
106
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
107
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
108
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
109
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
110
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'lib/osheet/version'
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = 'osheet'
|
9
|
+
s.version = Osheet::Version.to_s
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
12
|
+
s.rdoc_options = %w(--main README.rdoc)
|
13
|
+
s.summary = "A DSL for generating spreadsheets that doesn't totally suck - pronounced 'Oh sheeeeeet!'"
|
14
|
+
s.author = 'Kelly Redding'
|
15
|
+
s.email = 'kelly@kelredd.com'
|
16
|
+
s.homepage = 'http://github.com/kelredd/osheet'
|
17
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
|
18
|
+
# s.executables = ['osheet']
|
19
|
+
|
20
|
+
s.add_development_dependency("shoulda", [">= 2.10.0"])
|
21
|
+
s.add_development_dependency("kelredd-useful", [">= 0.3.0"])
|
22
|
+
|
23
|
+
s.add_dependency("spreadsheet", [">= 0.6.4"])
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
27
|
+
pkg.gem_spec = spec
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::TestTask.new do |t|
|
31
|
+
t.libs << 'test'
|
32
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
33
|
+
t.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
|
39
|
+
Rcov::RcovTask.new(:coverage) do |t|
|
40
|
+
t.libs = ['test']
|
41
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
42
|
+
t.verbose = true
|
43
|
+
t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby']
|
44
|
+
end
|
45
|
+
|
46
|
+
task :default => :coverage
|
47
|
+
|
48
|
+
rescue LoadError
|
49
|
+
warn "\n**** Install rcov (sudo gem install relevance-rcov) to get coverage stats ****\n"
|
50
|
+
task :default => :test
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Generate the gemspec to serve this gem'
|
54
|
+
task :gemspec do
|
55
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
56
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
57
|
+
puts "Created gemspec: #{file}"
|
58
|
+
end
|
data/lib/osheet/base.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module Osheet
|
2
|
+
class Base
|
3
|
+
|
4
|
+
ATTRS = [:class, :style]
|
5
|
+
ATTRS.each {|a| attr_accessor a}
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def configure(*args, &block)
|
10
|
+
it = new(*args)
|
11
|
+
block.call(it) if block
|
12
|
+
it
|
13
|
+
end
|
14
|
+
|
15
|
+
def has(things)
|
16
|
+
things.each do |collection, item|
|
17
|
+
clean_collection = cleanup_name(collection)
|
18
|
+
clean_item = cleanup_name(item)
|
19
|
+
|
20
|
+
define_method(clean_collection) do
|
21
|
+
fetch_value(clean_collection, [])
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method(clean_item.downcase) do |*arge, &block|
|
25
|
+
fetch_collection(clean_collection, []) << \
|
26
|
+
osheet_constantize("Osheet::#{clean_item}").configure(*args, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def needs(thing)
|
32
|
+
clean_need = cleanup_name(thing)
|
33
|
+
|
34
|
+
define_method(clean_need) do
|
35
|
+
fetch_value(clean_need)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(args={})
|
42
|
+
set_args ATTRS, args
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
class << self
|
48
|
+
|
49
|
+
def cleanup_name(name)
|
50
|
+
name.to_s.gsub(/\W/,'')
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_value(clean_name, default_value=nil)
|
54
|
+
instance_variable_get("@#{clean_name}") ||
|
55
|
+
instance_variable_set("@#{clean_name}", default_value)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_args(arg_list, args)
|
61
|
+
if args && args.kind_of?(::Hash)
|
62
|
+
arg_list.each {|a| instance_variable_set("@#{a}", args[a])}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
if Module.method(:const_get).arity == 1
|
69
|
+
def osheet_constantize(camel_cased_word)
|
70
|
+
names = camel_cased_word.split('::')
|
71
|
+
names.shift if names.empty? || names.first.empty?
|
72
|
+
|
73
|
+
constant = ::Object
|
74
|
+
names.each do |name|
|
75
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
76
|
+
end
|
77
|
+
constant
|
78
|
+
end unless ::String.respond_to?('constantize')
|
79
|
+
else
|
80
|
+
# Ruby 1.9 introduces an inherit argument for Module#const_get and
|
81
|
+
# #const_defined? and changes their default behavior.
|
82
|
+
def osheet_constantize(camel_cased_word) #:nodoc:
|
83
|
+
names = camel_cased_word.split('::')
|
84
|
+
names.shift if names.empty? || names.first.empty?
|
85
|
+
|
86
|
+
constant = ::Object
|
87
|
+
names.each do |name|
|
88
|
+
constant = constant.const_get(name, false) || constant.const_missing(name)
|
89
|
+
end
|
90
|
+
constant
|
91
|
+
end unless ::String.respond_to?('constantize')
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
data/lib/osheet/cell.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'osheet/base'
|
2
|
+
|
3
|
+
module Osheet
|
4
|
+
class Cell < Osheet::Base
|
5
|
+
|
6
|
+
attr_accessor :data
|
7
|
+
|
8
|
+
ATTRS = [:format, :rowspan, :colspan]
|
9
|
+
ATTRS.each {|a| attr_accessor a}
|
10
|
+
|
11
|
+
def initialize(data='', args={})
|
12
|
+
@data = data
|
13
|
+
set_args ATTRS, args
|
14
|
+
super(args)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/osheet/row.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'osheet/base'
|
2
|
+
require 'osheet/worksheet'
|
3
|
+
|
4
|
+
# === Usage
|
5
|
+
#
|
6
|
+
# require 'osheet'
|
7
|
+
#
|
8
|
+
# Osheet::Workbook.configure do |book|
|
9
|
+
# book.worksheet ...
|
10
|
+
# book.worksheet ...
|
11
|
+
# end
|
12
|
+
|
13
|
+
module Osheet
|
14
|
+
class Workbook < Osheet::Base
|
15
|
+
|
16
|
+
has :worksheets => "Worksheet"
|
17
|
+
|
18
|
+
def initialize(args={})
|
19
|
+
super(args)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'osheet/base'
|
2
|
+
require 'osheet/column'
|
3
|
+
require 'osheet/row'
|
4
|
+
|
5
|
+
# === Usage
|
6
|
+
#
|
7
|
+
# require 'osheet'
|
8
|
+
#
|
9
|
+
# Osheet::Workbook.configure do |book|
|
10
|
+
# book.worksheet ...
|
11
|
+
# book.worksheet ...
|
12
|
+
# end
|
13
|
+
|
14
|
+
module Osheet
|
15
|
+
class Worksheet < Osheet::Base
|
16
|
+
|
17
|
+
attr_reader :name
|
18
|
+
|
19
|
+
needs :workbook
|
20
|
+
has :columns => "Column"
|
21
|
+
has :rows => "Row"
|
22
|
+
|
23
|
+
def initialize(name=nil, args={})
|
24
|
+
@name = name
|
25
|
+
super(args)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/osheet.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'osheet/base'
|
2
|
+
require 'osheet/workbook'
|
3
|
+
require 'osheet/worksheet'
|
4
|
+
|
5
|
+
module Osheet
|
6
|
+
SPREADSHEET_TYPE = "Excel"
|
7
|
+
MIME_TYPE = "application/vnd.ms-excel"
|
8
|
+
=begin
|
9
|
+
@@config = Config.new
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
# Configuration accessors for Rack::Less
|
14
|
+
# (see config.rb for details)
|
15
|
+
def configure
|
16
|
+
yield @@config if block_given?
|
17
|
+
end
|
18
|
+
def config
|
19
|
+
@@config
|
20
|
+
end
|
21
|
+
def config=(value)
|
22
|
+
@@config = value
|
23
|
+
end
|
24
|
+
|
25
|
+
# Combinations config convenience method
|
26
|
+
def combinations(key=nil)
|
27
|
+
@@config.combinations(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
=end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osheet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kelly Redding
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-23 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 10
|
30
|
+
- 0
|
31
|
+
version: 2.10.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: kelredd-useful
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: 0.3.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: spreadsheet
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 6
|
58
|
+
- 4
|
59
|
+
version: 0.6.4
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
description:
|
63
|
+
email: kelly@kelredd.com
|
64
|
+
executables: []
|
65
|
+
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
extra_rdoc_files:
|
69
|
+
- README.rdoc
|
70
|
+
files:
|
71
|
+
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- lib/osheet/base.rb
|
74
|
+
- lib/osheet/cell.rb
|
75
|
+
- lib/osheet/column.rb
|
76
|
+
- lib/osheet/row.rb
|
77
|
+
- lib/osheet/version.rb
|
78
|
+
- lib/osheet/workbook.rb
|
79
|
+
- lib/osheet/worksheet.rb
|
80
|
+
- lib/osheet.rb
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/kelredd/osheet
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --main
|
88
|
+
- README.rdoc
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: A DSL for generating spreadsheets that doesn't totally suck - pronounced 'Oh sheeeeeet!'
|
112
|
+
test_files: []
|
113
|
+
|