csv-excel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a367f9511f4614dd2ded29130cb9e1dc1d929b65f72289cc18ffb17e33d8b061
4
+ data.tar.gz: 9c9acfde72d40eeb08d84106fd5cd46ad13771fd58a9deb2201ef31067a740b5
5
+ SHA512:
6
+ metadata.gz: e533e7918c81fcea54a7b23435927ecfc50fa4743dbb94d5aafe286fe586432dfdf872f534207d5720f6b3a39f304aed9520467d4529bb7c236a7d6e28db28ec
7
+ data.tar.gz: 30271a4a3626e3d777c1e1989c34fc52d54677e7f6568679ac9d616bf6919ec2678b4b4cc56de72bda886bd61e07502434b0fa959c05bdcac1de10d459f51612
@@ -0,0 +1,63 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.6
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install bundler
31
+ command: |
32
+ gem install bundler -v "2.0.1"
33
+ - run:
34
+ name: install dependencies
35
+ command: |
36
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
37
+
38
+ - save_cache:
39
+ paths:
40
+ - ./vendor/bundle
41
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
42
+
43
+ # run tests!
44
+ - run:
45
+ name: run tests
46
+ command: |
47
+ mkdir /tmp/test-results
48
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
49
+ circleci tests split --split-by=timings)"
50
+
51
+ bundle exec rspec \
52
+ --format progress \
53
+ --format RspecJunitFormatter \
54
+ --out /tmp/test-results/rspec.xml \
55
+ --format progress \
56
+ $TEST_FILES
57
+
58
+ # collect reports
59
+ - store_test_results:
60
+ path: /tmp/test-results
61
+ - store_artifacts:
62
+ path: /tmp/test-results
63
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,41 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "bin/**/*"
4
+ TargetRubyVersion: 2.6
5
+
6
+ Layout/EmptyLinesAroundAccessModifier:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Enabled: false
11
+
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+
15
+ Performance/StartWith:
16
+ Enabled: false
17
+
18
+ Style/BlockDelimiters:
19
+ Exclude:
20
+ - "spec/**/*_spec.rb"
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/FrozenStringLiteralComment:
26
+ Enabled: false
27
+
28
+ Style/HashSyntax:
29
+ Exclude:
30
+ - "Rakefile"
31
+
32
+ Style/PercentLiteralDelimiters:
33
+ PreferredDelimiters:
34
+ '%r': '()'
35
+
36
+ Style/RegexpLiteral:
37
+ Enabled: false
38
+
39
+ Style/StringLiterals:
40
+ EnforcedStyle: double_quotes
41
+
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Unreleased
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in csv-excel.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ csv-excel (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.2)
12
+ parallel (1.17.0)
13
+ parser (2.6.2.1)
14
+ ast (~> 2.4.0)
15
+ psych (3.1.0)
16
+ rainbow (3.0.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.3)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+ rspec_junit_formatter (0.4.1)
32
+ rspec-core (>= 2, < 4, != 2.12.0)
33
+ rubocop (0.67.2)
34
+ jaro_winkler (~> 1.5.1)
35
+ parallel (~> 1.10)
36
+ parser (>= 2.5, != 2.5.1.1)
37
+ psych (>= 3.1.0)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 1.6)
41
+ ruby-progressbar (1.10.0)
42
+ unicode-display_width (1.5.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 2.0)
49
+ csv-excel!
50
+ rake (~> 10.0)
51
+ rspec (~> 3.8.0)
52
+ rspec_junit_formatter (~> 0.4.1)
53
+ rubocop (~> 0.67.2)
54
+
55
+ BUNDLED WITH
56
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 labocho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # CSV::Excel
2
+
3
+ CSV::Excel extends Ruby's `csv` stdlib to generate CSV file for Microsoft Excel.
4
+ This converts...
5
+
6
+ - Time/Date/DateTime object to Excel's date/time format (`yyyy/mm/dd`, `yyyy/mm/dd hh:mm:ss`).
7
+ - String to `="foo"` form for avoiding unexpected type casting (eg. Zero leading phone number, hyphen delimited street address).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'csv-excel'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install csv-excel
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "csv/excel"
29
+
30
+ buffer = ""
31
+
32
+ csv = CSV.new(buffer, for_excel: true)
33
+ csv << ["012", "12", "🍣", 123, Date.new(2019, 4, 1), Time.new(2019, 4, 1, 12, 34, 56)]
34
+
35
+ # Excel reads csv as Shift_JIS by default.
36
+ # Please add BOM to indicate UTF-8 encoding.
37
+ File.write("out.csv", CSV::Excel::UTF8BOM + buffer)
38
+
39
+ # Open Finder/Explorer, and double-click `out.csv`!
40
+ ```
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/labocho/csv-excel.
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "csv/excel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/csv-excel.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "csv/excel/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "csv-excel"
7
+ spec.version = CSV::Excel::VERSION
8
+ spec.authors = ["labocho"]
9
+ spec.email = ["labocho@penguinlab.jp"]
10
+
11
+ spec.summary = "Extend `csv` stdlib to generate CSV file for Microsft Excel"
12
+ spec.description = "Extend `csv` stdlib to generate CSV file for Microsft Excel"
13
+ spec.homepage = "https://github.com/labocho/csv-excel"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/labocho/csv-excel"
21
+ spec.metadata["changelog_uri"] = "https://github.com/labocho/csv-excel/blob/master/CHANGELOG.md"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r(^exe/)) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.required_ruby_version = ">= 2.6"
37
+
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.8.0"
41
+ spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
42
+ spec.add_development_dependency "rubocop", "~> 0.67.2"
43
+ end
data/lib/csv/excel.rb ADDED
@@ -0,0 +1,48 @@
1
+ require "csv"
2
+ require "csv/excel/version"
3
+
4
+ class CSV
5
+ module Excel
6
+ UTF8BOM = -"\xEF\xBB\xBF"
7
+
8
+ class Error < StandardError; end
9
+
10
+ def initialize(data, **options)
11
+ @for_excel = options.delete(:for_excel)
12
+ options[:force_quotes] = true if @for_excel
13
+ super(data, **options)
14
+ end
15
+
16
+ private
17
+ def writer_options
18
+ super.merge(for_excel: @for_excel)
19
+ end
20
+ end
21
+
22
+ class Writer
23
+ module Excel
24
+ DATE_FORMAT = -"%Y/%m/%d"
25
+ TIME_FORMAT = -"%Y/%m/%d %H:%M:%S"
26
+
27
+ def quote_field(field)
28
+ return super unless @options[:for_excel]
29
+
30
+ case field
31
+ when Date
32
+ super(field.strftime(DATE_FORMAT))
33
+ when Time, DateTime
34
+ super(field.strftime(TIME_FORMAT))
35
+ when String
36
+ quoted = super
37
+ encoded_assign_character = "=".encode(quoted.encoding)
38
+ encoded_assign_character + quoted
39
+ else
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ CSV.prepend CSV::Excel
48
+ CSV::Writer.prepend CSV::Writer::Excel
@@ -0,0 +1,7 @@
1
+ require "csv"
2
+
3
+ class CSV
4
+ module Excel
5
+ VERSION = "0.1.0".freeze
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv-excel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - labocho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.8.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.67.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.67.2
83
+ description: Extend `csv` stdlib to generate CSV file for Microsft Excel
84
+ email:
85
+ - labocho@penguinlab.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".circleci/config.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - CHANGELOG.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/rspec
102
+ - bin/rubocop
103
+ - bin/setup
104
+ - csv-excel.gemspec
105
+ - lib/csv/excel.rb
106
+ - lib/csv/excel/version.rb
107
+ homepage: https://github.com/labocho/csv-excel
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ homepage_uri: https://github.com/labocho/csv-excel
112
+ source_code_uri: https://github.com/labocho/csv-excel
113
+ changelog_uri: https://github.com/labocho/csv-excel/blob/master/CHANGELOG.md
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '2.6'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Extend `csv` stdlib to generate CSV file for Microsft Excel
133
+ test_files: []