babaloa 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 6dfa2ceb70c00495a1b6a702fe5d5ba5b69b37d41086f60230112603caf592bc
4
- data.tar.gz: 59b2e1729b54655849b58f753c9de74bec202c90202d8a3a4d908b741f273301
3
+ metadata.gz: 504a9eb60037d436fe931f54f40ea31b90a321c7d1f8bcfc824699c1b42e6554
4
+ data.tar.gz: e8aa654cb29fdc99586bec36dc581817ba0215e0b7ed09f6803e21ac9cf76634
5
5
  SHA512:
6
- metadata.gz: f02b2153b16e6d047cbdb4293d68c541a77f5efc0183e0ba7f11ee43d456539f230a216fd92ca57893779e362bcb09b5db799b221d1f2633beafe73111c6d9f5
7
- data.tar.gz: b27e8beed3308fd5ca307ce5086c6906b5f45416bec87a1e26cafff120cb06fe181801389e17c28e969c40fb2e275ce4c55ea99b1901e905674514726d5c98a9
6
+ metadata.gz: aae6439a396cab2139730381e65e9071cf6af9828646191ec1ba6b9a9d193f2948a039ade8540088b0001175912c5c38b3ac3f12f4c3558bcee4112563886421
7
+ data.tar.gz: ffa8ef6242d3a8bae401f772e0e1524ef56ca95c80c83edf2f7632613176aae5f77cb02b084a50bf42330f0317bf2c28afe933a42fef8f4b108cdd2a23cab99a
@@ -0,0 +1,68 @@
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.3
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
+ branches:
20
+ only:
21
+ - master
22
+
23
+ steps:
24
+ - checkout
25
+
26
+ # Download and cache dependencies
27
+ - restore_cache:
28
+ keys:
29
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
30
+ # fallback to using the latest cache if no exact match is found
31
+ - v1-dependencies-
32
+
33
+ - run:
34
+ name: install dependencies
35
+ command: |
36
+ gem install bundler:2.0.1
37
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
38
+
39
+ - save_cache:
40
+ paths:
41
+ - ./vendor/bundle
42
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
43
+
44
+ # Database setup
45
+ # - run: bundle exec rake db:create
46
+ # - run: bundle exec rake db:schema:load
47
+
48
+ # run tests!
49
+ - run:
50
+ name: run tests
51
+ command: |
52
+ mkdir /tmp/test-results
53
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
54
+ circleci tests split --split-by=timings)"
55
+
56
+ bundle exec rspec \
57
+ --format progress \
58
+ --format RspecJunitFormatter \
59
+ --out /tmp/test-results/rspec.xml \
60
+ --format progress \
61
+ $TEST_FILES
62
+
63
+ # collect reports
64
+ - store_test_results:
65
+ path: /tmp/test-results
66
+ - store_artifacts:
67
+ path: /tmp/test-results
68
+ destination: test-results
data/Gemfile CHANGED
@@ -3,4 +3,7 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in babaloa.gemspec
4
4
  gemspec
5
5
 
6
- gem "byebug", platform: :mri, group: %i(development test)
6
+ group :development, :test do
7
+ gem "byebug", platform: :mri
8
+ gem "rspec_junit_formatter"
9
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- babaloa (0.1.0)
4
+ babaloa (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -22,6 +22,8 @@ GEM
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
23
  rspec-support (~> 3.8.0)
24
24
  rspec-support (3.8.0)
25
+ rspec_junit_formatter (0.4.1)
26
+ rspec-core (>= 2, < 4, != 2.12.0)
25
27
 
26
28
  PLATFORMS
27
29
  ruby
@@ -32,6 +34,7 @@ DEPENDENCIES
32
34
  byebug
33
35
  rake (~> 10.0)
34
36
  rspec (~> 3.0)
37
+ rspec_junit_formatter
35
38
 
36
39
  BUNDLED WITH
37
40
  2.0.1
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # Babaloa
1
+ [![CircleCI](https://circleci.com/gh/belion-freee/babaloa/tree/master.svg?style=svg&circle-token=b9268fffd3d7fe1e2d7639b718a4c307c761c607)](https://circleci.com/gh/belion-freee/babaloa/tree/master)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/babaloa`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ # Babaloa
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This is a gem that will convert to CSV if you pass an array. In addition to conversion, sorting, column specification, and translation can be optionally specified.
6
+ You can also register default settings in initializers.
6
7
 
7
8
  ## Installation
8
9
 
@@ -21,18 +22,105 @@ Or install it yourself as:
21
22
  $ gem install babaloa
22
23
 
23
24
  ## Usage
25
+ It is very easy to use. Pass an array as an argument. CSV file is generated.
26
+
27
+ ```ruby
28
+ arr = [["col1", "col2", "col3"],["row1-1", "row1-2", "row1-3"],["row2-1", "row2-2", "row2-3"]]
29
+ Babaloa.to_csv(arr) # => "col1,col2,col3\nrow1-1,row1-2,row1-3\nrow2-1,row2-2,row2-3\n"
30
+ ```
31
+
32
+ You can also use Hash for the contents of the array. Like this.
33
+
34
+ ```ruby
35
+ arr = [{"col1" => "row1-1", "col2" => "row1-2", "col3" => "row1-3"},{ "col1" => "row2-1", "col2" => "row2-2", "col3" => "row2-3"}]
36
+ Babaloa.to_csv(arr) # => "col1,col2,col3\nrow1-1,row1-2,row1-3\nrow2-1,row2-2,row2-3\n"
37
+ ```
38
+
39
+ ## Options
40
+ Introduces the available options.
41
+
42
+ ### Sort options
43
+ You can sort content for using sort options.
44
+ You can use option value with Hash(only use desc) or String, Symbol.
45
+ **Be sure to use the same hash key type as the header name** to be specified. It does not move if the type is different. In addition, in case of comparing with `2, 3, 100` note that the order will be `100, 2, 3` when comparing by character string.
46
+
47
+ ```ruby
48
+ arr = [{ "col1" => "row2-1", "col2" => "row2-2", "col3" => "row2-3"},{"col1" => "row1-1", "col2" => "row1-2", "col3" => "row1-3"}]
49
+ Babaloa.to_csv(arr, sort: "col1") # => "col1,col2,col3\nrow1-1,row1-2,row1-3\nrow2-1,row2-2,row2-3\n"
50
+ ```
51
+
52
+ You can also use Hash for using desc. Like this.
53
+
54
+ ```ruby
55
+ arr = [{ "col1" => "row2-1", "col2" => "row2-2", "col3" => "row2-3"},{"col1" => "row1-1", "col2" => "row1-2", "col3" => "row1-3"}]
56
+ Babaloa.to_csv(arr, sort: "col1") # => col1,col2,col3\nrow2-1,row2-2,row2-3\nrow1-1,row1-2,row1-3\n"
57
+ ```
58
+
59
+ ### Only/Except options
60
+ You can sort content for using sort options if you use Hash for the contents of the array.
61
+ You can use option value with Array or Symbol.
24
62
 
25
- TODO: Write usage instructions here
63
+ ```ruby
64
+ arr = [{ "col1" => "row2-1", "col2" => "row2-2", "col3" => "row2-3"},{"col1" => "row1-1", "col2" => "row1-2", "col3" => "row1-3"}]
65
+ Babaloa.to_csv(arr, only: %i(col1, col2)) # => "col1,col2\nrow2-1,row2-2\nrow1-1,row1-2\n"
66
+ Babaloa.to_csv(arr, except: :col3) # => "col1,col2\nrow2-1,row2-2\nrow1-1,row1-2\n"
67
+ ```
68
+
69
+ ### Transrate options
70
+ You can transrate header for using t options.
71
+ You can only use option value with Hash.
72
+
73
+ ```ruby
74
+ arr = [{ "col1" => "row2-1", "col2" => "row2-2", "col3" => "row2-3"},{"col1" => "row1-1", "col2" => "row1-2", "col3" => "row1-3"}]
75
+ Babaloa.to_csv(arr, t: {"col1" => "一番目", "col2" => "二番目", "col3" => "三番目"}) # => "一番目,二番目,三番目\nrow1-1,row1-2,row1-3\nrow2-1,row2-2,row2-3\n"
76
+ ```
77
+
78
+ ## Initializer
79
+ You can set options by default in initializers.
80
+
81
+ ### default
82
+ Describes the settings applied to all csv output. The usage of the options is the same.
83
+
84
+ ```ruby
85
+ Babaloa.configure {|config|
86
+ config.default = {
87
+ except: %i(updated_at created_at),
88
+ sort: { id: :desc },
89
+ t: { id: "ID", name: "NAME", age: "AGE" }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### definition
95
+ Describe the settings that apply separately. The usage of the options is the same.
96
+
97
+ ```ruby
98
+ Babaloa.configure {|config|
99
+ config.definition = {
100
+ test: {
101
+ except: %i(updated_at created_at),
102
+ sort: { id: :desc },
103
+ t: { id: "ID", name: "NAME", age: "AGE" }
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ And use it like this.
110
+
111
+ ```ruby
112
+ Babaloa.to_csv(arr, name: :test)
113
+ ```
26
114
 
27
115
  ## Development
28
116
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
117
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `./qs spec` to run the tests. You can also run `./qs run app bin/console` for an interactive prompt that will allow you to experiment.
30
118
 
31
- 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).
119
+ To install this gem onto your local machine, run `./qs rake install`. To release a new version, update the version number in `version.rb`, and then run `./qs 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).
32
120
 
33
121
  ## Contributing
34
122
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/babaloa.
123
+ Bug reports and pull requests are welcome on GitHub at https://github.com/belion-freee/babaloa.
36
124
 
37
125
  ## License
38
126
 
data/lib/babaloa.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require "babaloa/version"
2
2
  require "babaloa/config"
3
3
  require "csv"
4
- require "byebug" # TODO: debugger
4
+
5
5
  module Babaloa
6
6
  class BabaloaError < StandardError; end
7
7
 
8
8
  class << self
9
9
  def to_csv(data, h = true, **options)
10
- raise ArgumentError, "data must be Array" unless data.is_a?(Array)
11
- raise ArgumentError, "content must be Array or Hash" unless data.empty? || data.first.is_a?(Array) || data.first.is_a?(Hash)
10
+ raise BabaloaError, "data must be Array" unless data.is_a?(Array)
11
+ raise BabaloaError, "content must be Array or Hash" unless data.empty? || data.first.is_a?(Array) || data.first.is_a?(Hash)
12
12
 
13
13
  if h && !data.empty?
14
14
  if data.first.is_a?(Hash)
@@ -24,10 +24,10 @@ module Babaloa
24
24
  end
25
25
 
26
26
  CSV.generate do |csv|
27
- csv << transrate_by(header, **options) if h && header
27
+ csv << transrate_by(header.dup, **options) if h && header
28
28
  data.each{|res|
29
29
  if res.is_a?(Hash)
30
- raise ArgumentError, "Header required if content is Hash" unless h
30
+ raise BabaloaError, "Header required if content is Hash" unless h
31
31
  csv << header.map {|k| res[k] || res[k.to_s] }
32
32
  else
33
33
  csv << res
@@ -49,7 +49,7 @@ module Babaloa
49
49
  sort = header.index(sort.to_sym) if data.first.is_a?(Array)
50
50
  data.sort_by! {|col| col[sort] }
51
51
  else
52
- raise ArgumentError, "sort option must be Hash, Symbol, String."
52
+ raise BabaloaError, "sort option must be Hash, Symbol, String."
53
53
  end
54
54
 
55
55
  data
@@ -64,7 +64,7 @@ module Babaloa
64
64
  elsif only.is_a?(Symbol)
65
65
  header.select! {|k| only == k }
66
66
  else
67
- raise ArgumentError, "only option must be Array, Symbol"
67
+ raise BabaloaError, "only option must be Array, Symbol"
68
68
  end
69
69
 
70
70
  header
@@ -79,7 +79,7 @@ module Babaloa
79
79
  elsif except.is_a?(Symbol)
80
80
  header.reject! {|k| except == k }
81
81
  else
82
- raise ArgumentError, "except option must be Array, Symbol"
82
+ raise BabaloaError, "except option must be Array, Symbol"
83
83
  end
84
84
 
85
85
  header
@@ -92,7 +92,7 @@ module Babaloa
92
92
  if t.is_a?(Hash)
93
93
  header.map! {|k| t[k] || t[k.to_s] }.compact!
94
94
  else
95
- raise ArgumentError, "t option must be Hash"
95
+ raise BabaloaError, "t option must be Hash"
96
96
  end
97
97
 
98
98
  header
@@ -1,3 +1,3 @@
1
1
  module Babaloa
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babaloa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - belion-freee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-21 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".circleci/config.yml"
62
63
  - ".gitignore"
63
64
  - ".rspec"
64
- - ".travis.yml"
65
65
  - Dockerfile
66
66
  - Gemfile
67
67
  - Gemfile.lock
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.0
7
- before_install: gem install bundler -v 2.0.1