babaloa 0.1.3 → 0.1.4

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: 8c00fa46ca468031df5f9b69c9abe0f87345d6d018b56b961b00506482de4dc7
4
- data.tar.gz: 7d60b52c5efe8a43be10a75e4f41dd1c0f86f1f1db2becdb53a6af0774d75566
3
+ metadata.gz: c5202306d0fb523ce7eb9ff36eaa25bac96e1bb992c1b18fc4a4b01ce4ca243d
4
+ data.tar.gz: b7a39bceee3cf8f3703d982e532ca48c95e2b9562e323aa474d6a9cea9c96ae3
5
5
  SHA512:
6
- metadata.gz: ae9fa1fd251da634779493eb724ef504ed3e6d0be283886b0a170c8be8bab9b7836da1119c9f9a8fc3cfa9a28529619c74ed1a10c0bbfc41437e0662d819793f
7
- data.tar.gz: a96b4c84a25cb622617a62946e74d54551233ecfaf2cfbc8a713778fb3c8cea345a0d8d1ff1c2b758431c237158cfc58ed59657df002ec1f7d0977efa80ed04c
6
+ metadata.gz: af9671f14b1403bfb673af28417150701cf7210f53e4276620e2a2e3e4fd5893c7a2cb25543a779b76d8638d2fbda3ddc07e015ea0e4939b1541374546711587
7
+ data.tar.gz: 8ce736aa3d0e2bcb816637f93b8f9cd155a68569c64534cfb9f255581ca7733d2158b5523ee76b2fdd9de42edb6fa633be0f9f5ceedaa7b512d6f4194b16d065
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- babaloa (0.1.3)
4
+ babaloa (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -36,6 +36,15 @@ arr = [{"col1" => "row1-1", "col2" => "row1-2", "col3" => "row1-3"},{ "col1" =>
36
36
  Babaloa.to_csv(arr) # => "col1,col2,col3\nrow1-1,row1-2,row1-3\nrow2-1,row2-2,row2-3\n"
37
37
  ```
38
38
 
39
+ ### Ruby on Rails
40
+ If you use Ruby on Rails, you must to convert ActiveRecord object to Hash.
41
+ The easiest way is to add `map(&:attributes)` at the end of the search results.
42
+
43
+ ```ruby
44
+ arr = SomeModel.all.map(&:attributes)
45
+ Babaloa.to_csv(arr)
46
+ ```
47
+
39
48
  ## Options
40
49
  Introduces the available options.
41
50
 
@@ -116,7 +125,7 @@ Babaloa.to_csv(arr, name: :test)
116
125
 
117
126
  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.
118
127
 
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).
128
+ 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 build` and `./qs run gem push pkg/babaloa-x.x.x.gem`, which will push the `.gem` file to [rubygems.org](https://rubygems.org).
120
129
 
121
130
  ## Contributing
122
131
 
@@ -40,16 +40,19 @@ module Babaloa
40
40
  sort = options[:sort] || configuration.define(options[:name], :sort) || configuration.default[:sort]
41
41
  return data unless sort
42
42
 
43
- conv = proc {|v| v.is_a?(String) && v =~ /^\d+$/ ? v.to_i : v }
43
+ conv = proc {|h, k|
44
+ v = h[k] || h[k.to_s] || h[k.to_sym]
45
+ v.is_a?(String) && v =~ /^\d+$/ ? v.to_i : v
46
+ }
44
47
 
45
48
  if sort.is_a?(Hash)
46
49
  k, v = sort.first
47
50
  k = header.index(k.to_sym) if data.first.is_a?(Array)
48
- data.sort_by! {|col| conv.(col[k]) }
51
+ data.sort_by! {|col| conv.(col, k) }
49
52
  data.reverse! if v == :desc
50
- elsif sort.is_a?(Symbol) || sort.is_a?(String)
53
+ elsif is_s?(sort)
51
54
  sort = header.index(sort.to_sym) if data.first.is_a?(Array)
52
- data.sort_by! {|col| conv.(col[sort]) }
55
+ data.sort_by! {|col| conv.(col, sort) }
53
56
  else
54
57
  raise BabaloaError, "sort option must be Hash, Symbol, String."
55
58
  end
@@ -63,10 +66,10 @@ module Babaloa
63
66
 
64
67
  if only.is_a?(Array)
65
68
  header.select! {|k| only.include?(k) }
66
- elsif only.is_a?(Symbol)
67
- header.select! {|k| only == k }
69
+ elsif is_s?(only)
70
+ header.select! {|k| k == only.to_sym }
68
71
  else
69
- raise BabaloaError, "only option must be Array, Symbol"
72
+ raise BabaloaError, "only option must be Array, Symbol, String."
70
73
  end
71
74
 
72
75
  header
@@ -78,10 +81,10 @@ module Babaloa
78
81
 
79
82
  if except.is_a?(Array)
80
83
  header.reject! {|k| except.include?(k) }
81
- elsif except.is_a?(Symbol)
82
- header.reject! {|k| except == k }
84
+ elsif is_s?(except)
85
+ header.reject! {|k| k == except.to_sym }
83
86
  else
84
- raise BabaloaError, "except option must be Array, Symbol"
87
+ raise BabaloaError, "except option must be Array, Symbol, String."
85
88
  end
86
89
 
87
90
  header
@@ -92,12 +95,18 @@ module Babaloa
92
95
  return header unless t
93
96
 
94
97
  if t.is_a?(Hash)
95
- header.map! {|k| t[k] || t[k.to_s] }.compact!
98
+ header.map! {|k| t[k] || t[k.to_s] || k }.compact!
96
99
  else
97
100
  raise BabaloaError, "t option must be Hash"
98
101
  end
99
102
 
100
103
  header
101
104
  end
105
+
106
+ private
107
+
108
+ def is_s?(val)
109
+ val.is_a?(Symbol) || val.is_a?(String)
110
+ end
102
111
  end
103
112
  end
@@ -1,3 +1,3 @@
1
1
  module Babaloa
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
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.3
4
+ version: 0.1.4
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-23 00:00:00.000000000 Z
11
+ date: 2019-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler