excel-esv 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2df2df2ce669d424b4477df8e53cf1ba1b294f1d
4
- data.tar.gz: 64194135c8519c09ed8ce694c7e5623e1f480a5c
3
+ metadata.gz: 7f43f1221f2eb2bc5484f74786339827acb6c95b
4
+ data.tar.gz: 6180ee4ddd35c35e5d4149c61f3138d4b207f271
5
5
  SHA512:
6
- metadata.gz: 859d4c02c198bfeff440af26773203c74abcf33bf49e768dd244b700c0e6ce70cb0c77307e0b62b8fc742bd1fb14b1a30b2f63abeb6cc481a1867d630a378749
7
- data.tar.gz: e2c19b093f119cddd8e9bca7687ace2a9c684679aa4a5d19c98e4bc4338ce2e06b52e64166a367d85f612f88215cfe953044fe99ff53e5067d3b7ebb37fda10a
6
+ metadata.gz: ece4fd3a10785678c758c99cbf3a24441b267e0d76bb56639cf811900440b3d0a00ec98272d17b3283496e8ca8b2bff35050f1f21916d2ff71758cf02918ac40
7
+ data.tar.gz: 062d7892b8ff824ffef79341f4fd07d188e62b1cdb092d87e55ce0c59cfeb083d80dcbcf483ef6e12a07138dc36535fcf6d2ccaf2cebbb06406ec5c55511b802
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ESV
2
2
 
3
- Ruby library/gem for Excel generation with the ease of CSV generation.
3
+ Ruby library/gem for Excel parsing and generation with the ease of CSV.
4
4
 
5
5
  Exporting CSVs because Excel generation is too complex? No more!
6
6
 
@@ -9,6 +9,8 @@ CSVs can be difficult to open correctly, e.g. in Excel on Mac.
9
9
 
10
10
  ## Usage
11
11
 
12
+ ### Generate
13
+
12
14
  ```
13
15
  data = ESV.generate do |esv|
14
16
  esv << [ "Name", "Dogs", "Cats" ]
@@ -18,7 +20,14 @@ end
18
20
  File.write("/tmp/test.xls", data)
19
21
  ```
20
22
 
21
- ### Ruby on Rails
23
+ ### Parse
24
+
25
+ ```
26
+ excel = File.read("/tmp/test.xls")
27
+ output = ESV.parse(data) # => [ [ "Name", "Dogs", … ], … ]
28
+ ```
29
+
30
+ ### Generate in Ruby on Rails
22
31
 
23
32
  In `config/initializers/mime_types.rb`:
24
33
 
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/excel-esv.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ESV::VERSION
9
9
  spec.authors = ["Henrik Nyh"]
10
10
  spec.email = ["henrik@nyh.se"]
11
- spec.summary = %q{Excel generation with the ease of CSV generation.}
11
+ spec.summary = %q{Excel parsing and generation with the ease of CSV.}
12
12
  spec.homepage = "https://github.com/barsoom/excel-esv"
13
13
  spec.license = "MIT"
14
14
 
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "spreadsheet"
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
23
24
  end
@@ -0,0 +1,24 @@
1
+ class ESV::Generator
2
+ def initialize
3
+ @data_rows = []
4
+ end
5
+
6
+ def <<(row)
7
+ @data_rows << row
8
+ end
9
+
10
+ def render
11
+ book = Spreadsheet::Workbook.new
12
+ sheet = book.create_worksheet
13
+
14
+ @data_rows.each_with_index do |data_row, index|
15
+ row = sheet.row(index)
16
+ row.push(*data_row)
17
+ end
18
+
19
+ content = ""
20
+ fake_file = StringIO.new(content)
21
+ book.write(fake_file)
22
+ content
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
- class ESV
1
+ module ESV
2
2
  MIME_TYPE = "application/vnd.ms-excel"
3
3
  CONTENT_TYPE = "#{MIME_TYPE}; charset=utf-8"
4
4
 
data/lib/esv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- class ESV
2
- VERSION = "0.0.2"
1
+ module ESV
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/esv.rb CHANGED
@@ -1,34 +1,18 @@
1
1
  require "esv/version"
2
+ require "esv/generator"
2
3
  require "esv/rails_controller"
3
4
  require "spreadsheet"
4
5
 
5
- class ESV
6
+ module ESV
6
7
  def self.generate
7
- instance = new
8
- yield(instance)
9
- instance.render
8
+ generator = Generator.new
9
+ yield(generator)
10
+ generator.render
10
11
  end
11
12
 
12
- def initialize
13
- @data_rows = []
14
- end
15
-
16
- def <<(row)
17
- @data_rows << row
18
- end
19
-
20
- def render
21
- book = Spreadsheet::Workbook.new
22
- sheet = book.create_worksheet
23
-
24
- @data_rows.each_with_index do |data_row, index|
25
- row = sheet.row(index)
26
- row.push(*data_row)
27
- end
28
-
29
- content = ""
30
- fake_file = StringIO.new(content)
31
- book.write(fake_file)
32
- content
13
+ def self.parse(data)
14
+ fake_file = StringIO.new(data)
15
+ book = Spreadsheet.open(fake_file)
16
+ book.worksheet(0).to_a
33
17
  end
34
18
  end
data/spec/esv_spec.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "esv"
2
+
3
+ describe ESV, ".generate and .parse" do
4
+ it "works" do
5
+ data = ESV.generate do |esv|
6
+ esv << [ "Dogs", "Cats" ]
7
+ esv << [ 1, 2 ]
8
+ end
9
+
10
+ output = ESV.parse(data)
11
+
12
+ expect(output).to eq [
13
+ [ "Dogs", "Cats" ],
14
+ [ 1, 2 ],
15
+ ]
16
+ end
17
+ end
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel-esv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - henrik@nyh.se
@@ -60,15 +74,19 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".gitignore"
77
+ - ".rspec"
63
78
  - Gemfile
64
79
  - LICENSE.txt
65
80
  - README.md
66
81
  - Rakefile
67
82
  - excel-esv.gemspec
68
83
  - lib/esv.rb
84
+ - lib/esv/generator.rb
69
85
  - lib/esv/rails_controller.rb
70
86
  - lib/esv/version.rb
71
87
  - lib/excel-esv.rb
88
+ - spec/esv_spec.rb
89
+ - spec/spec_helper.rb
72
90
  homepage: https://github.com/barsoom/excel-esv
73
91
  licenses:
74
92
  - MIT
@@ -92,5 +110,7 @@ rubyforge_project:
92
110
  rubygems_version: 2.2.2
93
111
  signing_key:
94
112
  specification_version: 4
95
- summary: Excel generation with the ease of CSV generation.
96
- test_files: []
113
+ summary: Excel parsing and generation with the ease of CSV.
114
+ test_files:
115
+ - spec/esv_spec.rb
116
+ - spec/spec_helper.rb