array_hasher 0.1.4 → 0.1.5
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 +4 -4
- data/.rubocop.yml +138 -0
- data/.travis.yml +3 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -1
- data/README.md +3 -1
- data/Rakefile +1 -1
- data/array_hasher.gemspec +1 -0
- data/examples/base.rb +1 -3
- data/examples/csv.rb +1 -2
- data/examples/custom_type.rb +1 -2
- data/lib/array_hasher.rb +2 -0
- data/lib/array_hasher/formatter.rb +9 -6
- data/lib/array_hasher/version.rb +3 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 868889e1655542a502402c3f2a56165c6369ce58
|
4
|
+
data.tar.gz: 23e7cdc0eba7154d4f6a8c6d4f81b277d3f36a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7c8f29194a9849255c009791bcd2b9cf462b8b6ba398b4522e395d3c669a73df2d1c4f3fc0871c684f95808b79291541642e8a6c8bb56d27c3217b121289db5
|
7
|
+
data.tar.gz: 6e60a0a9378c926b0c43d10869dd4395be582b17d9e9f045a99d0b0804d2adb50508df23f60a4e5dd00c41b1f983014e38552802d80046041a513f5643f9cede
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
---
|
2
|
+
# https://github.com/rails/rails/blob/master/.rubocop.yml
|
3
|
+
#
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.4
|
6
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
7
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
8
|
+
DisabledByDefault: true
|
9
|
+
|
10
|
+
# Prefer &&/|| over and/or.
|
11
|
+
Style/AndOr:
|
12
|
+
Enabled: true
|
13
|
+
|
14
|
+
# Do not use braces for hash literals when they are the last argument of a
|
15
|
+
# method call.
|
16
|
+
Style/BracesAroundHashParameters:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
# Align `when` with `case`.
|
20
|
+
Layout/CaseIndentation:
|
21
|
+
Enabled: true
|
22
|
+
EnforcedStyle: end
|
23
|
+
IndentOneStep: false
|
24
|
+
|
25
|
+
# Align comments with method definitions.
|
26
|
+
Layout/CommentIndentation:
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
Layout/EmptyLineAfterMagicComment:
|
30
|
+
Enabled: true
|
31
|
+
|
32
|
+
# No extra empty lines.
|
33
|
+
Layout/EmptyLines:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
# In a regular class definition, no empty lines around the body.
|
37
|
+
Layout/EmptyLinesAroundClassBody:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
# In a regular method definition, no empty lines around the body.
|
41
|
+
Layout/EmptyLinesAroundMethodBody:
|
42
|
+
Enabled: true
|
43
|
+
|
44
|
+
# In a regular module definition, no empty lines around the body.
|
45
|
+
Layout/EmptyLinesAroundModuleBody:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
49
|
+
Style/HashSyntax:
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
53
|
+
# extra level of indentation.
|
54
|
+
Layout/IndentationConsistency:
|
55
|
+
Enabled: true
|
56
|
+
# EnforcedStyle: rails
|
57
|
+
|
58
|
+
# Two spaces, no tabs (for indentation).
|
59
|
+
Layout/IndentationWidth:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
Layout/SpaceAfterColon:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Layout/SpaceAfterComma:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
69
|
+
Enabled: true
|
70
|
+
|
71
|
+
Layout/SpaceAroundKeyword:
|
72
|
+
Enabled: true
|
73
|
+
|
74
|
+
Layout/SpaceAroundOperators:
|
75
|
+
Enabled: true
|
76
|
+
|
77
|
+
Layout/SpaceBeforeFirstArg:
|
78
|
+
Enabled: true
|
79
|
+
|
80
|
+
# Defining a method with parameters needs parentheses.
|
81
|
+
Style/MethodDefParentheses:
|
82
|
+
Enabled: true
|
83
|
+
|
84
|
+
# str = "abcda"
|
85
|
+
# str.gsub!("c", "b") # will raise a error, we cannot change string literal
|
86
|
+
Style/FrozenStringLiteralComment:
|
87
|
+
Enabled: true
|
88
|
+
EnforcedStyle: always
|
89
|
+
Include:
|
90
|
+
- 'app/**/*'
|
91
|
+
- 'lib/**/*'
|
92
|
+
|
93
|
+
# Use `foo {}` not `foo{}`.
|
94
|
+
Layout/SpaceBeforeBlockBraces:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
# Use `foo { bar }` not `foo {bar}`.
|
98
|
+
Layout/SpaceInsideBlockBraces:
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
102
|
+
Layout/SpaceInsideHashLiteralBraces:
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
Layout/SpaceInsideParens:
|
106
|
+
Enabled: true
|
107
|
+
|
108
|
+
# Check quotes usage according to lint rule below.
|
109
|
+
# Style/StringLiterals:
|
110
|
+
# Enabled: true
|
111
|
+
# EnforcedStyle: double_quotes
|
112
|
+
|
113
|
+
# Detect hard tabs, no hard tabs.
|
114
|
+
Layout/Tab:
|
115
|
+
Enabled: true
|
116
|
+
|
117
|
+
# Blank lines should not have any spaces.
|
118
|
+
Layout/TrailingBlankLines:
|
119
|
+
Enabled: true
|
120
|
+
|
121
|
+
# No trailing whitespace.
|
122
|
+
Layout/TrailingWhitespace:
|
123
|
+
Enabled: true
|
124
|
+
|
125
|
+
# Use quotes for string literals when they are enough.
|
126
|
+
# Style/UnneededPercentQ:
|
127
|
+
# Enabled: true
|
128
|
+
|
129
|
+
# Align `end` with the matching keyword or starting expression except for
|
130
|
+
# assignments, where it should be aligned with the LHS.
|
131
|
+
Lint/EndAlignment:
|
132
|
+
Enabled: true
|
133
|
+
EnforcedStyleAlignWith: variable
|
134
|
+
|
135
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
136
|
+
Lint/RequireParentheses:
|
137
|
+
Enabled: true
|
138
|
+
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
array_hasher (0.1.
|
4
|
+
array_hasher (0.1.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
ast (2.4.0)
|
9
10
|
diff-lcs (1.3)
|
11
|
+
parallel (1.12.1)
|
12
|
+
parser (2.5.3.0)
|
13
|
+
ast (~> 2.4.0)
|
14
|
+
powerpack (0.1.2)
|
15
|
+
rainbow (3.0.0)
|
10
16
|
rake (10.5.0)
|
11
17
|
rspec (3.6.0)
|
12
18
|
rspec-core (~> 3.6.0)
|
@@ -21,6 +27,15 @@ GEM
|
|
21
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
28
|
rspec-support (~> 3.6.0)
|
23
29
|
rspec-support (3.6.0)
|
30
|
+
rubocop (0.52.1)
|
31
|
+
parallel (~> 1.10)
|
32
|
+
parser (>= 2.4.0.2, < 3.0)
|
33
|
+
powerpack (~> 0.1)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
37
|
+
ruby-progressbar (1.10.0)
|
38
|
+
unicode-display_width (1.4.0)
|
24
39
|
|
25
40
|
PLATFORMS
|
26
41
|
ruby
|
@@ -30,6 +45,7 @@ DEPENDENCIES
|
|
30
45
|
bundler (~> 1.16.a)
|
31
46
|
rake (~> 10.0)
|
32
47
|
rspec (~> 3.0)
|
48
|
+
rubocop (~> 0.52.1)
|
33
49
|
|
34
50
|
BUNDLED WITH
|
35
51
|
1.16.0
|
data/README.md
CHANGED
@@ -114,7 +114,7 @@ ArrayHasher.new_formatter(format)
|
|
114
114
|
|
115
115
|
|
116
116
|
### Examples
|
117
|
-
|
117
|
+
|
118
118
|
See [Here](./examples)
|
119
119
|
|
120
120
|
## Default Types
|
@@ -123,6 +123,8 @@ See [Here](./examples)
|
|
123
123
|
* `float` # convert string to float
|
124
124
|
* `string`: # to_s
|
125
125
|
* `time` # Time.parse(string)
|
126
|
+
* `date` # Date.parse(string)
|
127
|
+
* `json` # JSON.parse(string)
|
126
128
|
* `Proc` # format the value with your proc. we can define a Proc in our code only.
|
127
129
|
|
128
130
|
|
data/Rakefile
CHANGED
data/array_hasher.gemspec
CHANGED
data/examples/base.rb
CHANGED
@@ -2,8 +2,6 @@ require 'bundler/setup'
|
|
2
2
|
require 'array_hasher'
|
3
3
|
|
4
4
|
f = ArrayHasher.new_formatter([
|
5
|
-
[:a, :int], [:b, :float], [:c, proc {|v| v.split(',') }], [:d, nil, range: 3..-1]
|
5
|
+
[:a, :int], [:b, :float], [:c, proc { |v| v.split(',') }], [:d, nil, range: 3..-1]
|
6
6
|
])
|
7
7
|
puts f.parse(['number: 123', '$ 123.1', 'a,b,c', 'd1', 'd2', 'd3'])
|
8
|
-
|
9
|
-
|
data/examples/csv.rb
CHANGED
@@ -7,8 +7,7 @@ ArrayHasher.csv_each(File.expand_path('../test.csv', __FILE__)) do |line|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
puts "\nDefined 'bookname' wrap with <>"
|
10
|
-
ext_types = {bookname: proc {|v| "<#{v}>" }}
|
10
|
+
ext_types = { bookname: proc { |v| "<#{v}>" } }
|
11
11
|
ArrayHasher.csv_each(File.expand_path('../test.csv', __FILE__), ext_types) do |line|
|
12
12
|
puts line
|
13
13
|
end
|
14
|
-
|
data/examples/custom_type.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
f = ArrayHasher.new_formatter([
|
2
2
|
[:a, :int], [:b, :float], [:c, :my_arr], [:d, nil, range: 3..-1]
|
3
3
|
])
|
4
|
-
f.define_type(:my_arr) {|v| v.split(',').map(&:to_i) }
|
4
|
+
f.define_type(:my_arr) { |v| v.split(',').map(&:to_i) }
|
5
5
|
# or
|
6
6
|
# f.types[:my_arr] = proc {|v| v.split(',').map(&:to_i) }
|
7
7
|
puts f.parse(['number: 123', '$ 123.1', '1,2,3', 'd1', 'd2', 'd3'])
|
8
|
-
|
data/lib/array_hasher.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
module ArrayHasher
|
@@ -7,10 +9,12 @@ module ArrayHasher
|
|
7
9
|
REGEXP_EMPTY = /\A\s*\z/
|
8
10
|
|
9
11
|
TYPES = {
|
10
|
-
int: Proc.new {|v| (v.nil? || v =~ REGEXP_EMPTY) ? nil : v.gsub(/[^\d]+/, '').to_i },
|
11
|
-
float: Proc.new {|v| (v.nil? || v =~ REGEXP_EMPTY) ? nil :
|
12
|
-
string: Proc.new {|v| v.to_s },
|
13
|
-
time: Proc.new {|v| v ? Time.parse(v) : nil }
|
12
|
+
int: Proc.new { |v| (v.nil? || v =~ REGEXP_EMPTY) ? nil : v.gsub(/[^\d]+/, '').to_i },
|
13
|
+
float: Proc.new { |v| (v.nil? || v =~ REGEXP_EMPTY) ? nil : v.gsub(/[^\d\.]+/, '').to_f },
|
14
|
+
string: Proc.new { |v| v.to_s },
|
15
|
+
time: Proc.new { |v| v ? Time.parse(v) : nil },
|
16
|
+
json: Proc.new { |v| v ? JSON.parse(v) : nil },
|
17
|
+
date: Proc.new { |v| v ? Date.parse(v) : nil }
|
14
18
|
}
|
15
19
|
|
16
20
|
# cols:
|
@@ -29,7 +33,7 @@ module ArrayHasher
|
|
29
33
|
[
|
30
34
|
name ? name.to_sym : nil,
|
31
35
|
(type.nil? || type.is_a?(Proc)) ? type : type.to_sym,
|
32
|
-
(opts || {}).each_with_object({}) {|kv, r| r[kv[0].to_sym] = kv[1] }
|
36
|
+
(opts || {}).each_with_object({}) { |kv, r| r[kv[0].to_sym] = kv[1] }
|
33
37
|
]
|
34
38
|
end
|
35
39
|
end
|
@@ -59,4 +63,3 @@ module ArrayHasher
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
end
|
62
|
-
|
data/lib/array_hasher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_hasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiangzhi.xie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.52.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.52.1
|
55
69
|
description: Convert array to hash according to your defined formatter
|
56
70
|
email:
|
57
71
|
- xiejiangzhi@gmail.com
|
@@ -61,6 +75,7 @@ extra_rdoc_files: []
|
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
63
77
|
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
64
79
|
- ".travis.yml"
|
65
80
|
- Gemfile
|
66
81
|
- Gemfile.lock
|