excel-esv 0.0.7 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f4b522fea0806b72698bc419499675d9848f5e54
4
- data.tar.gz: 8c855b2015a8a1795144885e2e7c72a60d37487e
2
+ SHA256:
3
+ metadata.gz: 61b9d8716af48b7a32382ba6e9558a5f9f2afc71cb6ec0e6a380686dd91ea308
4
+ data.tar.gz: 8d737947eb7b20510cd234a5c23a033c5eaec2a8f90d22152c8c6892de99e271
5
5
  SHA512:
6
- metadata.gz: 4f1aa109f2887da7a834572e40ad4f1a7adcb8933076b58d3311ee768fa2c53144ecdb918fb70b837e98efffeefb43bbe5294788844015a2a2fb7ec2b5b99f72
7
- data.tar.gz: a5cdfc529d344daef68ff7eb6fd23ae80cd6697f84b6ae3151f8e6de0ce502db53fb0289391f910a7e7a3e13ceb59fa4baca267f14dffcd76b4095398d4dea48
6
+ metadata.gz: e72fa2c2685e9833c15d4ea0c6278b41ca0b8f45fe296ff81f6691652cd0b477f68e69365b9bc42b3d70024738361cd8805ab0d21885de875b028febab293d0d
7
+ data.tar.gz: 2dacf749dcc74944f9ad3cf2ef671e123a16f8665ecfab299541cd22c702663b9e168218675cfd75cc56ef1bac455b3d90f6f554f0d3549f71928931074808ea
@@ -0,0 +1,26 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ["3.0", "2.7", "2.6", "2.5"]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby ${{ matrix.ruby-version }}
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
25
+ - name: Run tests
26
+ run: bundle exec rake
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "tmp/**/*"
4
+ inherit_gem:
5
+ barsoom_utils: shared_rubocop.yml
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # 3.0.0
2
+
3
+ * Returns the last value of any formula cells instead of returning a `Spreadsheet::Formula`.
4
+ * Returns the URL of any link cells instead of returning a `Spreadsheet::Link`.
5
+
6
+ # 2.0.0
7
+
8
+ * `parse` now returns an actual nested `Array`, not array-like `Spreadsheet::Row` records.
9
+
10
+ # 1.0.0
11
+
12
+ * `send_excel` now supports a `filename:` argument, e.g. `send_excel(data, filename: "salaries.xls")`.
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in esv.gemspec
3
+ # Specify your gem's dependencies in excel-esv.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem "barsoom_utils", github: "barsoom/barsoom_utils"
8
+ gem "bundler"
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "rubocop"
12
+ end
data/README.md CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  Ruby library/gem for Excel parsing and generation with the ease of CSV.
4
4
 
5
- Exporting CSVs because Excel generation is too complex? No more!
5
+ Exporting CSVs because Excel generation is too complex? No more! CSVs can also be difficult to open correctly, e.g. in Excel on Mac.
6
6
 
7
- CSVs can be difficult to open correctly, e.g. in Excel on Mac.
7
+ ESV will read and generate XLS files. There is currently no XLSX support, but Pull Requests are welcome.
8
+
9
+ By design, ESV only reads and writes simple values like integers, floats, strings and dates/datetimes. When parsing a spreadsheet with formulas, you will get their last value, if known.
8
10
 
9
11
 
10
12
  ## Usage
@@ -83,6 +85,7 @@ class MyController < ApplicationController
83
85
  def show
84
86
  data = MyExcelDocument.generate("Rails")
85
87
  send_excel(data)
88
+ # or: send_excel(data, filename: "myfilename.xls")
86
89
  end
87
90
 
88
91
  def another_example
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/excel-esv.gemspec CHANGED
@@ -1,24 +1,20 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'esv/version'
4
+ require "esv/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "excel-esv"
8
8
  spec.version = ESV::VERSION
9
- spec.authors = ["Henrik Nyh"]
10
- spec.email = ["henrik@nyh.se"]
9
+ spec.authors = [ "Henrik Nyh" ]
10
+ spec.email = [ "henrik@nyh.se" ]
11
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
+ spec.metadata = { "rubygems_mfa_required" => "true" }
14
15
 
15
16
  spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
17
+ spec.require_paths = [ "lib" ]
19
18
 
20
19
  spec.add_dependency "spreadsheet"
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
24
20
  end
@@ -5,11 +5,12 @@ module ESV
5
5
  module RailsController
6
6
  private
7
7
 
8
- def send_excel(data)
8
+ def send_excel(data, filename: nil)
9
9
  send_data(
10
10
  data,
11
11
  type: ESV::CONTENT_TYPE,
12
12
  disposition: "attachment",
13
+ filename: filename,
13
14
  )
14
15
  end
15
16
  end
data/lib/esv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ESV
2
- VERSION = "0.0.7"
2
+ VERSION = "3.0.1"
3
3
  end
data/lib/esv.rb CHANGED
@@ -25,7 +25,15 @@ module ESV
25
25
  worksheet_count = book.worksheets.length
26
26
  raise "Expected 1 worksheet, found #{worksheet_count}." if worksheet_count > 1
27
27
 
28
- book.worksheet(0).to_a
28
+ book.worksheet(0).to_a.map(&:to_a).map { |row|
29
+ row.map { |cell|
30
+ case cell
31
+ when Spreadsheet::Formula then cell.value
32
+ when Spreadsheet::Link then cell.href
33
+ else cell
34
+ end
35
+ }
36
+ }
29
37
  end
30
38
 
31
39
  def self.parse_file(path)
data/spec/esv_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "esv"
2
2
 
3
- describe ESV, ".generate and .parse" do
3
+ RSpec.describe ESV, ".generate and .parse" do
4
4
  it "works" do
5
5
  data = ESV.generate do |esv|
6
6
  esv << [ "Dogs", "Cats" ]
@@ -16,19 +16,68 @@ describe ESV, ".generate and .parse" do
16
16
  end
17
17
  end
18
18
 
19
- describe ESV, ".parse" do
19
+ RSpec.describe ESV, ".parse" do
20
20
  it "raises if there's more than one worksheet" do
21
+ excel_file_with_two_worksheets = generate_excel_file do |sheet, book|
22
+ book.create_worksheet
23
+ end
24
+
21
25
  expect {
22
26
  ESV.parse(excel_file_with_two_worksheets)
23
27
  }.to raise_error(/Expected 1 worksheet, found 2/)
24
28
  end
25
29
 
30
+ it "ignores formatting, always returning a plain array of data" do
31
+ excel_file_with_formatting = generate_excel_file do |sheet|
32
+ sheet.row(0).replace([ 1, 2 ])
33
+ sheet.row(0).default_format = Spreadsheet::Format.new(color: :blue)
34
+ end
35
+
36
+ output = ESV.parse(excel_file_with_formatting)
37
+
38
+ expect(output).to eq [
39
+ [ 1, 2 ],
40
+ ]
41
+
42
+ expect(output[0].class).to eq Array
43
+ end
44
+
45
+ it "returns the last value of a formula cell" do
46
+ excel_file_with_formula = generate_excel_file do |sheet|
47
+ formula = Spreadsheet::Formula.new
48
+ formula.value = "two"
49
+ sheet.row(0).replace([ "one", formula ])
50
+ end
51
+
52
+ output = ESV.parse(excel_file_with_formula)
53
+
54
+ expect(output).to eq [
55
+ [ "one", "two" ],
56
+ ]
57
+ expect(output[0].class).to eq Array
58
+ end
59
+
60
+
61
+ it "returns the URL of a link cell" do
62
+ excel_file_with_link = generate_excel_file do |sheet|
63
+ link = Spreadsheet::Link.new("https://example.com", "desc", "foo")
64
+ sheet.row(0).replace([ "one", link ])
65
+ end
66
+ output = ESV.parse(excel_file_with_link)
67
+ expect(output).to eq [
68
+ [ "one", "https://example.com#foo" ],
69
+ ]
70
+
71
+ expect(output[0][1].class).to eq String
72
+ end
73
+
26
74
  private
27
75
 
28
- def excel_file_with_two_worksheets
76
+ def generate_excel_file(&block)
29
77
  book = Spreadsheet::Workbook.new
30
- book.create_worksheet
31
- book.create_worksheet
78
+ sheet = book.create_worksheet
79
+
80
+ block.call(sheet, book)
32
81
 
33
82
  data = ""
34
83
  fake_file = StringIO.new(data)
@@ -37,7 +86,7 @@ describe ESV, ".parse" do
37
86
  end
38
87
  end
39
88
 
40
- describe ESV, ".generate_file and .parse_file" do
89
+ RSpec.describe ESV, ".generate_file and .parse_file" do
41
90
  before do
42
91
  @file = Tempfile.new("esv")
43
92
  end
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,4 @@
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
1
  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
2
  # These two settings work together to allow you to limit a spec run
22
3
  # to individual examples or groups you care about by tagging them with
23
4
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
@@ -32,7 +13,7 @@ RSpec.configure do |config|
32
13
  # Use the documentation formatter for detailed output,
33
14
  # unless a formatter has already been configured
34
15
  # (e.g. via a command-line flag).
35
- config.default_formatter = 'doc'
16
+ config.default_formatter = "doc"
36
17
  end
37
18
 
38
19
  # Print the 10 slowest examples and example groups at the
@@ -45,6 +26,7 @@ RSpec.configure do |config|
45
26
  # the seed, which is printed after each run.
46
27
  # --seed 1234
47
28
  config.order = :random
29
+ config.disable_monkey_patching!
48
30
 
49
31
  # Seed global randomization in this process using the `--seed` CLI option.
50
32
  # Setting this allows you to use `--seed` to deterministically reproduce
@@ -62,17 +44,11 @@ RSpec.configure do |config|
62
44
  expectations.syntax = :expect
63
45
  end
64
46
 
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
47
  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
48
  mocks.syntax = :expect
72
49
 
73
50
  # Prevents you from mocking or stubbing a method that does not exist on
74
51
  # a real object. This is generally recommended.
75
52
  mocks.verify_partial_doubles = true
76
53
  end
77
- =end
78
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel-esv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spreadsheet
@@ -24,48 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.7'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.7'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
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'
69
27
  description:
70
28
  email:
71
29
  - henrik@nyh.se
@@ -73,8 +31,11 @@ executables: []
73
31
  extensions: []
74
32
  extra_rdoc_files: []
75
33
  files:
34
+ - ".github/workflows/ci.yml"
76
35
  - ".gitignore"
77
36
  - ".rspec"
37
+ - ".rubocop.yml"
38
+ - CHANGELOG.md
78
39
  - Gemfile
79
40
  - LICENSE.txt
80
41
  - README.md
@@ -90,7 +51,8 @@ files:
90
51
  homepage: https://github.com/barsoom/excel-esv
91
52
  licenses:
92
53
  - MIT
93
- metadata: {}
54
+ metadata:
55
+ rubygems_mfa_required: 'true'
94
56
  post_install_message:
95
57
  rdoc_options: []
96
58
  require_paths:
@@ -106,11 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
68
  - !ruby/object:Gem::Version
107
69
  version: '0'
108
70
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.4.8
71
+ rubygems_version: 3.2.28
111
72
  signing_key:
112
73
  specification_version: 4
113
74
  summary: Excel parsing and generation with the ease of CSV.
114
- test_files:
115
- - spec/esv_spec.rb
116
- - spec/spec_helper.rb
75
+ test_files: []