extract 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.document +5 -0
  2. data/.lre +1 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +27 -0
  5. data/Gemfile.lock +108 -0
  6. data/Guardfile +27 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.rdoc +19 -0
  9. data/Rakefile +49 -0
  10. data/VERSION +1 -0
  11. data/extract.gemspec +128 -0
  12. data/lib/extract.rb +39 -0
  13. data/lib/extract/excel_formulas.rb +44 -0
  14. data/lib/extract/formula.treetop +66 -0
  15. data/lib/extract/math.treetop +33 -0
  16. data/lib/extract/math_calc.rb +111 -0
  17. data/lib/extract/parser.rb +90 -0
  18. data/lib/extract/persist/sheet.rb +26 -0
  19. data/lib/extract/sheet.rb +85 -0
  20. data/lib/extract/sheet_comp.rb +7 -0
  21. data/lib/extract/sheet_definition.rb +127 -0
  22. data/lib/extract/tree/base.rb +7 -0
  23. data/lib/extract/tree/cell.rb +33 -0
  24. data/lib/extract/tree/cond_exp.rb +25 -0
  25. data/lib/extract/tree/formula.rb +24 -0
  26. data/lib/extract/tree/formula_args.rb +30 -0
  27. data/lib/extract/tree/math.rb +106 -0
  28. data/lib/extract/tree/num.rb +18 -0
  29. data/lib/extract/tree/operator.rb +9 -0
  30. data/lib/extract/tree/range.rb +58 -0
  31. data/lib/extract/tree/string.rb +12 -0
  32. data/samples/baseball.xlsx +0 -0
  33. data/samples/div.xlsx +0 -0
  34. data/spec/config/mongoid.yml +6 -0
  35. data/spec/deps_spec.rb +48 -0
  36. data/spec/extract_spec.rb +44 -0
  37. data/spec/math_spec.rb +52 -0
  38. data/spec/parser_spec.rb +145 -0
  39. data/spec/persist_spec.rb +34 -0
  40. data/spec/sheet_definition_spec.rb +46 -0
  41. data/spec/sheet_spec.rb +51 -0
  42. data/spec/spec_helper.rb +68 -0
  43. data/vol/excel_test.rb +55 -0
  44. data/vol/parse_test.rb +8 -0
  45. data/vol/scratch.rb +61 -0
  46. data/vol/web.rb +0 -0
  47. data/vol/yaml_test.rb +4 -0
  48. data/web/file.tmp +0 -0
  49. data/web/file.xlsx +0 -0
  50. data/web/main.rb +59 -0
  51. data/web/mongoid.yml +6 -0
  52. data/web/views/index.haml +39 -0
  53. data/web/views/upload.haml +13 -0
  54. metadata +311 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.lre ADDED
@@ -0,0 +1 @@
1
+ load "lib/extract.rb"
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.2"
12
+ gem "jeweler", "~> 1.8.4"
13
+ #gem "rcov", ">= 0"
14
+ end
15
+
16
+ gem 'guard'
17
+ gem 'guard-rspec'
18
+ gem 'guard-spork'
19
+
20
+ gem 'mharris_ext'
21
+ gem 'treetop'
22
+
23
+ gem 'lre'
24
+ gem 'roo'
25
+
26
+ gem 'rb-fsevent', '~> 0.9.1'
27
+ gem 'mongoid'
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.12)
5
+ activesupport (= 3.2.12)
6
+ builder (~> 3.0.0)
7
+ activesupport (3.2.12)
8
+ i18n (~> 0.6)
9
+ multi_json (~> 1.0)
10
+ builder (3.0.4)
11
+ childprocess (0.3.7)
12
+ ffi (~> 1.0, >= 1.0.6)
13
+ coderay (1.0.8)
14
+ diff-lcs (1.1.3)
15
+ facets (2.9.3)
16
+ fattr (2.2.1)
17
+ ffi (1.3.1)
18
+ git (1.2.5)
19
+ guard (1.6.2)
20
+ listen (>= 0.6.0)
21
+ lumberjack (>= 1.0.2)
22
+ pry (>= 0.9.10)
23
+ terminal-table (>= 1.4.3)
24
+ thor (>= 0.14.6)
25
+ guard-rspec (1.2.1)
26
+ guard (>= 1.1)
27
+ guard-spork (1.4.2)
28
+ childprocess (>= 0.2.3)
29
+ guard (>= 1.1)
30
+ spork (>= 0.8.4)
31
+ i18n (0.6.1)
32
+ jeweler (1.8.4)
33
+ bundler (~> 1.0)
34
+ git (>= 1.2.5)
35
+ rake
36
+ rdoc
37
+ json (1.7.7)
38
+ listen (0.7.2)
39
+ lre (0.3.0)
40
+ fattr
41
+ mharris_ext
42
+ watchr
43
+ lumberjack (1.0.2)
44
+ method_source (0.8.1)
45
+ mharris_ext (1.6.0)
46
+ facets
47
+ fattr
48
+ mongoid (3.0.14)
49
+ activemodel (~> 3.1)
50
+ moped (~> 1.1)
51
+ origin (~> 1.0)
52
+ tzinfo (~> 0.3.22)
53
+ moped (1.3.1)
54
+ multi_json (1.6.0)
55
+ nokogiri (1.5.6)
56
+ origin (1.0.11)
57
+ polyglot (0.3.3)
58
+ pry (0.9.11.4)
59
+ coderay (~> 1.0.5)
60
+ method_source (~> 0.8)
61
+ slop (~> 3.4)
62
+ rake (10.0.3)
63
+ rb-fsevent (0.9.1)
64
+ rdoc (3.12.1)
65
+ json (~> 1.4)
66
+ roo (1.10.2)
67
+ nokogiri (>= 1.5.6)
68
+ rubyzip (>= 0.9.9)
69
+ spreadsheet (> 0.6.4)
70
+ rspec (2.8.0)
71
+ rspec-core (~> 2.8.0)
72
+ rspec-expectations (~> 2.8.0)
73
+ rspec-mocks (~> 2.8.0)
74
+ rspec-core (2.8.0)
75
+ rspec-expectations (2.8.0)
76
+ diff-lcs (~> 1.1.2)
77
+ rspec-mocks (2.8.0)
78
+ ruby-ole (1.2.11.6)
79
+ rubyzip (0.9.9)
80
+ slop (3.4.3)
81
+ spork (0.9.2)
82
+ spreadsheet (0.7.9)
83
+ ruby-ole (>= 1.0)
84
+ terminal-table (1.4.5)
85
+ thor (0.17.0)
86
+ treetop (1.4.12)
87
+ polyglot
88
+ polyglot (>= 0.3.1)
89
+ tzinfo (0.3.35)
90
+ watchr (0.7)
91
+
92
+ PLATFORMS
93
+ ruby
94
+
95
+ DEPENDENCIES
96
+ bundler (~> 1.2)
97
+ guard
98
+ guard-rspec
99
+ guard-spork
100
+ jeweler (~> 1.8.4)
101
+ lre
102
+ mharris_ext
103
+ mongoid
104
+ rb-fsevent (~> 0.9.1)
105
+ rdoc (~> 3.12)
106
+ roo
107
+ rspec (~> 2.8.0)
108
+ treetop
data/Guardfile ADDED
@@ -0,0 +1,27 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+
5
+
6
+
7
+ guard 'rspec', :cli => "--drb" do
8
+ watch(%r{^spec/.+_spec\.rb$})
9
+ watch(%r{^lib/(.+)\.rb$}) { "spec" } # { |m| "spec/lib/#{m[1]}_spec.rb" }
10
+ watch(%r{^lib/(.+)\.treetop$}) { "spec" }
11
+ watch('spec/spec_helper.rb') { "spec" }
12
+ end
13
+
14
+
15
+
16
+
17
+ guard 'spork' do
18
+ watch('config/application.rb')
19
+ watch('config/environment.rb')
20
+ watch('config/environments/test.rb')
21
+ watch(%r{^config/initializers/.+\.rb$})
22
+ watch('Gemfile')
23
+ watch('Gemfile.lock')
24
+ watch('spec/spec_helper.rb') { :rspec }
25
+ watch('test/test_helper.rb') { :test_unit }
26
+ watch(%r{features/support/}) { :cucumber }
27
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Mike Harris
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = extract
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to extract
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Mike Harris. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "extract"
18
+ gem.homepage = "http://github.com/mharris717/extract"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{extract}
21
+ gem.description = %Q{extract}
22
+ gem.email = "mharris717@gmail.com"
23
+ gem.authors = ["Mike Harris"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "extract #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/extract.gemspec ADDED
@@ -0,0 +1,128 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "extract"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mike Harris"]
12
+ s.date = "2013-02-21"
13
+ s.description = "extract"
14
+ s.email = "mharris717@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".lre",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "Guardfile",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "extract.gemspec",
31
+ "lib/extract.rb",
32
+ "lib/extract/excel_formulas.rb",
33
+ "lib/extract/formula.treetop",
34
+ "lib/extract/math.treetop",
35
+ "lib/extract/math_calc.rb",
36
+ "lib/extract/parser.rb",
37
+ "lib/extract/persist/sheet.rb",
38
+ "lib/extract/sheet.rb",
39
+ "lib/extract/sheet_comp.rb",
40
+ "lib/extract/sheet_definition.rb",
41
+ "lib/extract/tree/base.rb",
42
+ "lib/extract/tree/cell.rb",
43
+ "lib/extract/tree/cond_exp.rb",
44
+ "lib/extract/tree/formula.rb",
45
+ "lib/extract/tree/formula_args.rb",
46
+ "lib/extract/tree/math.rb",
47
+ "lib/extract/tree/num.rb",
48
+ "lib/extract/tree/operator.rb",
49
+ "lib/extract/tree/range.rb",
50
+ "lib/extract/tree/string.rb",
51
+ "samples/baseball.xlsx",
52
+ "samples/div.xlsx",
53
+ "spec/config/mongoid.yml",
54
+ "spec/deps_spec.rb",
55
+ "spec/extract_spec.rb",
56
+ "spec/math_spec.rb",
57
+ "spec/parser_spec.rb",
58
+ "spec/persist_spec.rb",
59
+ "spec/sheet_definition_spec.rb",
60
+ "spec/sheet_spec.rb",
61
+ "spec/spec_helper.rb",
62
+ "vol/excel_test.rb",
63
+ "vol/parse_test.rb",
64
+ "vol/scratch.rb",
65
+ "vol/web.rb",
66
+ "vol/yaml_test.rb",
67
+ "web/file.tmp",
68
+ "web/file.xlsx",
69
+ "web/main.rb",
70
+ "web/mongoid.yml",
71
+ "web/views/index.haml",
72
+ "web/views/upload.haml"
73
+ ]
74
+ s.homepage = "http://github.com/mharris717/extract"
75
+ s.licenses = ["MIT"]
76
+ s.require_paths = ["lib"]
77
+ s.rubygems_version = "1.8.23"
78
+ s.summary = "extract"
79
+
80
+ if s.respond_to? :specification_version then
81
+ s.specification_version = 3
82
+
83
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
84
+ s.add_runtime_dependency(%q<guard>, [">= 0"])
85
+ s.add_runtime_dependency(%q<guard-rspec>, [">= 0"])
86
+ s.add_runtime_dependency(%q<guard-spork>, [">= 0"])
87
+ s.add_runtime_dependency(%q<mharris_ext>, [">= 0"])
88
+ s.add_runtime_dependency(%q<treetop>, [">= 0"])
89
+ s.add_runtime_dependency(%q<lre>, [">= 0"])
90
+ s.add_runtime_dependency(%q<roo>, [">= 0"])
91
+ s.add_runtime_dependency(%q<rb-fsevent>, ["~> 0.9.1"])
92
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
93
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
94
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
95
+ s.add_development_dependency(%q<bundler>, ["~> 1.2"])
96
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
97
+ else
98
+ s.add_dependency(%q<guard>, [">= 0"])
99
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
100
+ s.add_dependency(%q<guard-spork>, [">= 0"])
101
+ s.add_dependency(%q<mharris_ext>, [">= 0"])
102
+ s.add_dependency(%q<treetop>, [">= 0"])
103
+ s.add_dependency(%q<lre>, [">= 0"])
104
+ s.add_dependency(%q<roo>, [">= 0"])
105
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9.1"])
106
+ s.add_dependency(%q<mongoid>, [">= 0"])
107
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
108
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
109
+ s.add_dependency(%q<bundler>, ["~> 1.2"])
110
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
111
+ end
112
+ else
113
+ s.add_dependency(%q<guard>, [">= 0"])
114
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
115
+ s.add_dependency(%q<guard-spork>, [">= 0"])
116
+ s.add_dependency(%q<mharris_ext>, [">= 0"])
117
+ s.add_dependency(%q<treetop>, [">= 0"])
118
+ s.add_dependency(%q<lre>, [">= 0"])
119
+ s.add_dependency(%q<roo>, [">= 0"])
120
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9.1"])
121
+ s.add_dependency(%q<mongoid>, [">= 0"])
122
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
123
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
124
+ s.add_dependency(%q<bundler>, ["~> 1.2"])
125
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
126
+ end
127
+ end
128
+
data/lib/extract.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Extract
2
+ end
3
+
4
+ require 'mharris_ext'
5
+ require 'treetop'
6
+ require 'ostruct'
7
+
8
+ require 'roo'
9
+
10
+ require 'mongoid'
11
+
12
+ class Object
13
+ def blank?
14
+ to_s.strip == ""
15
+ end
16
+ def present?
17
+ !blank?
18
+ end
19
+ end
20
+
21
+ class Numeric
22
+ def fact
23
+ return 1 if self == 0
24
+ return self if self <= 2
25
+ self.to_i * (self.to_i-1).fact
26
+ end
27
+ end
28
+
29
+ %w(parser sheet excel_formulas math_calc sheet_definition).each do |f|
30
+ load File.expand_path(File.dirname(__FILE__)) + "/extract/#{f}.rb"
31
+ end
32
+
33
+ %w(base range cond_exp formula formula_args math num cell operator string).each do |f|
34
+ load File.expand_path(File.dirname(__FILE__)) + "/extract/tree/#{f}.rb"
35
+ end
36
+
37
+ %w(sheet).each do |f|
38
+ load File.expand_path(File.dirname(__FILE__)) + "/extract/persist/#{f}.rb"
39
+ end
@@ -0,0 +1,44 @@
1
+ module Extract
2
+ class ExcelFormulas
3
+ def double(i)
4
+ i * 2
5
+ end
6
+ def sum(*args)
7
+ args.flatten.inject(0) { |s,i| s + (i || 0) }
8
+ end
9
+ def if(c,a,b)
10
+ res = c ? a : b
11
+ #puts [c,a,b].inspect
12
+ res
13
+ end
14
+ def max(*args)
15
+ args.flatten.select { |x| x }.sort.reverse.first
16
+ end
17
+ def vlookup(lookup_val,range,col_num)
18
+ range.each do |row|
19
+ if row[0] == lookup_val
20
+ return row[col_num-1]
21
+ end
22
+ end
23
+ nil
24
+ end
25
+ def sqrt(num)
26
+ if num.present?
27
+ (num.to_f) ** 0.5
28
+ else
29
+ nil
30
+ end
31
+ end
32
+
33
+ def combin(n,k)
34
+ #puts "combin #{n} #{k}"
35
+ n.fact / (k.fact * (n-k).fact)
36
+ end
37
+
38
+ class << self
39
+ def method_missing(sym,*args,&b)
40
+ new.send(sym,*args,&b)
41
+ end
42
+ end
43
+ end
44
+ end