normalizy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +379 -32
  4. data/lib/normalizy/config.rb +7 -3
  5. data/lib/normalizy/extensions.rb +11 -7
  6. data/lib/normalizy/filters/date.rb +44 -0
  7. data/lib/normalizy/filters/money.rb +38 -0
  8. data/lib/normalizy/filters/number.rb +4 -3
  9. data/lib/normalizy/filters/percent.rb +38 -0
  10. data/lib/normalizy/rspec/matcher.rb +2 -0
  11. data/lib/normalizy/version.rb +1 -1
  12. data/spec/normalizy/config/add_spec.rb +3 -0
  13. data/spec/normalizy/config/alias_spec.rb +7 -13
  14. data/spec/normalizy/config/initialize_spec.rb +5 -2
  15. data/spec/normalizy/config/normalizy_raws_spec.rb +1 -1
  16. data/spec/normalizy/extensions/{apply_normalizations_spec.rb → apply_normalizy_spec.rb} +36 -28
  17. data/spec/normalizy/extensions/filters/date_spec.rb +34 -0
  18. data/spec/normalizy/extensions/filters/money_spec.rb +40 -0
  19. data/spec/normalizy/extensions/filters/number_spec.rb +13 -0
  20. data/spec/normalizy/extensions/filters/percent_spec.rb +40 -0
  21. data/spec/normalizy/extensions/filters/strip_spec.rb +21 -0
  22. data/spec/normalizy/extensions/normalizy_rules_spec.rb +1 -1
  23. data/spec/normalizy/filters/date_spec.rb +56 -0
  24. data/spec/normalizy/filters/money_spec.rb +155 -0
  25. data/spec/normalizy/filters/number_spec.rb +25 -9
  26. data/spec/normalizy/filters/percent_spec.rb +155 -0
  27. data/spec/rails_helper.rb +4 -0
  28. data/spec/support/db/schema.rb +8 -3
  29. data/spec/support/filters/blacklist_1.rb +11 -0
  30. data/spec/support/filters/blacklist_2.rb +13 -0
  31. data/spec/support/filters/blacklist_block.rb +11 -0
  32. data/spec/support/models/user.rb +1 -1
  33. metadata +29 -8
  34. data/spec/normalizy/extensions/normalizy_spec.rb +0 -11
  35. data/spec/support/filters/blacklist_filter.rb +0 -15
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Normalizy::Filters::Money do
6
+ context 'with default options' do
7
+ it { expect(subject.call('')).to eq nil }
8
+
9
+ it { expect(subject.call(1)).to be 1 }
10
+ it { expect(subject.call(1.70)).to be 1.70 }
11
+ it { expect(subject.call(103.70)).to be 103.70 }
12
+ it { expect(subject.call(1030.70)).to be 1030.70 }
13
+ it { expect(subject.call(10_300.70)).to be 10_300.70 }
14
+
15
+ it { expect(subject.call('0')).to eq '0.00' }
16
+ it { expect(subject.call('1.70')).to eq '1.70' }
17
+ it { expect(subject.call('103.70')).to eq '103.70' }
18
+ it { expect(subject.call('1030.70')).to eq '1030.70' }
19
+ it { expect(subject.call('10300.70')).to eq '10300.70' }
20
+
21
+ it { expect(subject.call('R$ 1')).to eq '1.00' }
22
+ it { expect(subject.call('R$ 1.70')).to eq '1.70' }
23
+ it { expect(subject.call('R$ 103.70')).to eq '103.70' }
24
+ it { expect(subject.call('R$ 1030.70')).to eq '1030.70' }
25
+ it { expect(subject.call('R$ 10300.70')).to eq '10300.70' }
26
+ end
27
+
28
+ context 'with :cast' do
29
+ context 'when value has two decimal precision' do
30
+ it { expect(subject.call('1.70' , cast: :to_f)).to be 1.7 }
31
+ it { expect(subject.call('103.70' , cast: :to_f)).to be 103.7 }
32
+ it { expect(subject.call('1030.70' , cast: :to_f)).to be 1030.7 }
33
+ it { expect(subject.call('10300.70', cast: :to_f)).to be 10_300.7 }
34
+
35
+ it { expect(subject.call('R$ 1' , cast: :to_f)).to be 1.0 }
36
+ it { expect(subject.call('R$ 1.70' , cast: :to_f)).to be 1.7 }
37
+ it { expect(subject.call('R$ 103.70' , cast: :to_f)).to be 103.7 }
38
+ it { expect(subject.call('R$ 1030.70' , cast: :to_f)).to be 1030.7 }
39
+ it { expect(subject.call('R$ 10300.70', cast: :to_f)).to be 10_300.7 }
40
+ end
41
+
42
+ context 'when value has one decimal precision' do
43
+ it { expect(subject.call('1.7' , cast: :to_f)).to eq 1.7 }
44
+ it { expect(subject.call('103.7' , cast: :to_f)).to eq 103.7 }
45
+ it { expect(subject.call('1030.7' , cast: :to_f)).to eq 1030.7 }
46
+ it { expect(subject.call('10300.7', cast: :to_f)).to eq 10_300.7 }
47
+
48
+ it { expect(subject.call('R$ 1.7' , cast: :to_f)).to eq 1.7 }
49
+ it { expect(subject.call('R$ 103.7' , cast: :to_f)).to eq 103.7 }
50
+ it { expect(subject.call('R$ 1030.7' , cast: :to_f)).to eq 1030.7 }
51
+ it { expect(subject.call('R$ 10300.7', cast: :to_f)).to eq 10_300.7 }
52
+
53
+ context 'and calls cast' do
54
+ it { expect(subject.call('1.7' , cast: :to_f)).to be 1.7 }
55
+ it { expect(subject.call('103.7' , cast: :to_f)).to be 103.7 }
56
+ it { expect(subject.call('1030.7' , cast: :to_f)).to be 1030.7 }
57
+ it { expect(subject.call('10300.7', cast: :to_f)).to be 10_300.7 }
58
+
59
+ it { expect(subject.call('R$ 1.7' , cast: :to_f)).to be 1.7 }
60
+ it { expect(subject.call('R$ 103.7' , cast: :to_f)).to be 103.7 }
61
+ it { expect(subject.call('R$ 1030.7' , cast: :to_f)).to be 1030.7 }
62
+ it { expect(subject.call('R$ 10300.7', cast: :to_f)).to be 10_300.7 }
63
+ end
64
+ end
65
+
66
+ context 'with no decimal precision' do
67
+ it { expect(subject.call('1', type: :cents)).to eq '100' }
68
+ end
69
+ end
70
+
71
+ context 'with :type options' do
72
+ context 'as :cents' do
73
+ it { expect(subject.call('', type: :cents)).to eq nil }
74
+
75
+ it { expect(subject.call(1 , type: :cents)).to be 1 }
76
+ it { expect(subject.call(1.70 , type: :cents)).to be 1.70 }
77
+ it { expect(subject.call(103.70 , type: :cents)).to be 103.70 }
78
+ it { expect(subject.call(1030.70 , type: :cents)).to be 1030.70 }
79
+ it { expect(subject.call(10_300.70, type: :cents)).to be 10_300.70 }
80
+
81
+ context 'with two decimal precision' do
82
+ it { expect(subject.call('1.70' , type: :cents)).to eq '170' }
83
+ it { expect(subject.call('103.70' , type: :cents)).to eq '10370' }
84
+ it { expect(subject.call('1030.70' , type: :cents)).to eq '103070' }
85
+ it { expect(subject.call('10300.70', type: :cents)).to eq '1030070' }
86
+
87
+ it { expect(subject.call('R$ 1' , type: :cents)).to eq '100' }
88
+ it { expect(subject.call('R$ 1.70' , type: :cents)).to eq '170' }
89
+ it { expect(subject.call('R$ 103.70' , type: :cents)).to eq '10370' }
90
+ it { expect(subject.call('R$ 1030.70' , type: :cents)).to eq '103070' }
91
+ it { expect(subject.call('R$ 10300.70', type: :cents)).to eq '1030070' }
92
+
93
+ context 'with :cast' do
94
+ it { expect(subject.call('1.70' , cast: :to_f, type: :cents)).to be 170.0 }
95
+ it { expect(subject.call('103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
96
+ it { expect(subject.call('1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
97
+ it { expect(subject.call('10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
98
+
99
+ it { expect(subject.call('R$ 1' , cast: :to_f, type: :cents)).to be 100.0 }
100
+ it { expect(subject.call('R$ 1.70' , cast: :to_f, type: :cents)).to be 170.0 }
101
+ it { expect(subject.call('R$ 103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
102
+ it { expect(subject.call('R$ 1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
103
+ it { expect(subject.call('R$ 10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
104
+ end
105
+ end
106
+
107
+ context 'with one decimal precision' do
108
+ it { expect(subject.call('1.7' , type: :cents)).to eq '170' }
109
+ it { expect(subject.call('103.7' , type: :cents)).to eq '10370' }
110
+ it { expect(subject.call('1030.7' , type: :cents)).to eq '103070' }
111
+ it { expect(subject.call('10300.7', type: :cents)).to eq '1030070' }
112
+
113
+ it { expect(subject.call('R$ 1.7' , type: :cents)).to eq '170' }
114
+ it { expect(subject.call('R$ 103.7' , type: :cents)).to eq '10370' }
115
+ it { expect(subject.call('R$ 1030.7' , type: :cents)).to eq '103070' }
116
+ it { expect(subject.call('R$ 10300.7', type: :cents)).to eq '1030070' }
117
+
118
+ context 'with :cast' do
119
+ it { expect(subject.call('1.7' , cast: :to_f, type: :cents)).to be 170.0 }
120
+ it { expect(subject.call('103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
121
+ it { expect(subject.call('1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
122
+ it { expect(subject.call('10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
123
+
124
+ it { expect(subject.call('R$ 1.7' , cast: :to_f, type: :cents)).to be 170.0 }
125
+ it { expect(subject.call('R$ 103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
126
+ it { expect(subject.call('R$ 1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
127
+ it { expect(subject.call('R$ 10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
128
+ end
129
+ end
130
+
131
+ context 'with no decimal precision' do
132
+ it { expect(subject.call('1', type: :cents)).to eq '100' }
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'with :separator options' do
138
+ context 'provided via options rule' do
139
+ it { expect(subject.call('1-2', separator: '-')).to eq '1.20' }
140
+ end
141
+
142
+ context 'provided I18n' do
143
+ before do
144
+ allow(I18n).to receive(:t).with('currency.format.separator', default: '.') { 'x' }
145
+ allow(I18n).to receive(:t).with('currency.format.precision', default: 2) { 2 }
146
+ end
147
+
148
+ it { expect(subject.call('1x2')).to eq '1.20' }
149
+ end
150
+
151
+ context 'when not provided' do
152
+ it { expect(subject.call('1.2')).to eq '1.20' }
153
+ end
154
+ end
155
+ end
@@ -3,13 +3,29 @@
3
3
  require 'rails_helper'
4
4
 
5
5
  RSpec.describe Normalizy::Filters::Number do
6
- it { expect(subject.call('abcdefghijklmnopkrstuvxyz')).to eq nil }
7
- it { expect(subject.call('ABCDEFGHIJKLMNOPKRSTUVXYZ')).to eq nil }
8
- it { expect(subject.call('áéíóúàâêôãõ')).to eq nil }
9
- it { expect(subject.call('0123456789')).to eq 123_456_789 }
10
- it { expect(subject.call("\n")).to eq nil }
11
- it { expect(subject.call(42)).to eq 42 }
12
- it { expect(subject.call(nil)).to eq nil }
13
- it { expect(subject.call('nil')).to eq nil }
14
- it { expect(subject.call('')).to eq nil }
6
+ context 'with no cast' do
7
+ it { expect(subject.call('abcdefghijklmnopkrstuvxyz')).to eq nil }
8
+ it { expect(subject.call('ABCDEFGHIJKLMNOPKRSTUVXYZ')).to eq nil }
9
+ it { expect(subject.call('áéíóúàâêôãõ')).to eq nil }
10
+ it { expect(subject.call('0123456789')).to eq '0123456789' }
11
+ it { expect(subject.call('012345x6789')).to eq '0123456789' }
12
+ it { expect(subject.call("\n")).to eq nil }
13
+ it { expect(subject.call(42)).to eq 42 }
14
+ it { expect(subject.call(nil)).to eq nil }
15
+ it { expect(subject.call('nil')).to eq nil }
16
+ it { expect(subject.call('')).to eq nil }
17
+ end
18
+
19
+ context 'with :cast' do
20
+ it { expect(subject.call('abcdefghijklmnopkrstuvxyz', cast: :to_i)).to eq nil }
21
+ it { expect(subject.call('ABCDEFGHIJKLMNOPKRSTUVXYZ', cast: :to_i)).to eq nil }
22
+ it { expect(subject.call('áéíóúàâêôãõ', cast: :to_i)).to eq nil }
23
+ it { expect(subject.call('0123456789', cast: :to_i)).to eq 123_456_789 }
24
+ it { expect(subject.call('012345x6789', cast: :to_i)).to eq 123_456_789 }
25
+ it { expect(subject.call("\n", cast: :to_i)).to eq nil }
26
+ it { expect(subject.call(42, cast: :to_i)).to eq 42 }
27
+ it { expect(subject.call(nil, cast: :to_i)).to eq nil }
28
+ it { expect(subject.call('nil', cast: :to_i)).to eq nil }
29
+ it { expect(subject.call('', cast: :to_i)).to eq nil }
30
+ end
15
31
  end
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Normalizy::Filters::Percent do
6
+ context 'with default options' do
7
+ it { expect(subject.call('')).to eq nil }
8
+
9
+ it { expect(subject.call(1)).to be 1 }
10
+ it { expect(subject.call(1.70)).to be 1.70 }
11
+ it { expect(subject.call(103.70)).to be 103.70 }
12
+ it { expect(subject.call(1030.70)).to be 1030.70 }
13
+ it { expect(subject.call(10_300.70)).to be 10_300.70 }
14
+
15
+ it { expect(subject.call('0')).to eq '0.00' }
16
+ it { expect(subject.call('1.70')).to eq '1.70' }
17
+ it { expect(subject.call('103.70')).to eq '103.70' }
18
+ it { expect(subject.call('1030.70')).to eq '1030.70' }
19
+ it { expect(subject.call('10300.70')).to eq '10300.70' }
20
+
21
+ it { expect(subject.call('1 %')).to eq '1.00' }
22
+ it { expect(subject.call('1.70 %')).to eq '1.70' }
23
+ it { expect(subject.call('103.70 %')).to eq '103.70' }
24
+ it { expect(subject.call('1030.70 %')).to eq '1030.70' }
25
+ it { expect(subject.call('10300.70 %')).to eq '10300.70' }
26
+ end
27
+
28
+ context 'with :cast' do
29
+ context 'when value has two decimal precision' do
30
+ it { expect(subject.call('1.70' , cast: :to_f)).to be 1.7 }
31
+ it { expect(subject.call('103.70' , cast: :to_f)).to be 103.7 }
32
+ it { expect(subject.call('1030.70' , cast: :to_f)).to be 1030.7 }
33
+ it { expect(subject.call('10300.70', cast: :to_f)).to be 10_300.7 }
34
+
35
+ it { expect(subject.call('1 %' , cast: :to_f)).to be 1.0 }
36
+ it { expect(subject.call('1.70 %' , cast: :to_f)).to be 1.7 }
37
+ it { expect(subject.call('103.70 %' , cast: :to_f)).to be 103.7 }
38
+ it { expect(subject.call('1030.70 %' , cast: :to_f)).to be 1030.7 }
39
+ it { expect(subject.call('10300.70 %', cast: :to_f)).to be 10_300.7 }
40
+ end
41
+
42
+ context 'when value has one decimal precision' do
43
+ it { expect(subject.call('1.7' , cast: :to_f)).to eq 1.7 }
44
+ it { expect(subject.call('103.7' , cast: :to_f)).to eq 103.7 }
45
+ it { expect(subject.call('1030.7' , cast: :to_f)).to eq 1030.7 }
46
+ it { expect(subject.call('10300.7', cast: :to_f)).to eq 10_300.7 }
47
+
48
+ it { expect(subject.call('1.7 %' , cast: :to_f)).to eq 1.7 }
49
+ it { expect(subject.call('103.7 %' , cast: :to_f)).to eq 103.7 }
50
+ it { expect(subject.call('1030.7 %' , cast: :to_f)).to eq 1030.7 }
51
+ it { expect(subject.call('10300.7 %', cast: :to_f)).to eq 10_300.7 }
52
+
53
+ context 'and calls cast' do
54
+ it { expect(subject.call('1.7' , cast: :to_f)).to be 1.7 }
55
+ it { expect(subject.call('103.7' , cast: :to_f)).to be 103.7 }
56
+ it { expect(subject.call('1030.7' , cast: :to_f)).to be 1030.7 }
57
+ it { expect(subject.call('10300.7', cast: :to_f)).to be 10_300.7 }
58
+
59
+ it { expect(subject.call('1.7 %' , cast: :to_f)).to be 1.7 }
60
+ it { expect(subject.call('103.7 %' , cast: :to_f)).to be 103.7 }
61
+ it { expect(subject.call('1030.7 %' , cast: :to_f)).to be 1030.7 }
62
+ it { expect(subject.call('10300.7 %', cast: :to_f)).to be 10_300.7 }
63
+ end
64
+ end
65
+
66
+ context 'with no decimal precision' do
67
+ it { expect(subject.call('1', type: :cents)).to eq '100' }
68
+ end
69
+ end
70
+
71
+ context 'with :type options' do
72
+ context 'as :cents' do
73
+ it { expect(subject.call('', type: :cents)).to eq nil }
74
+
75
+ it { expect(subject.call(1 , type: :cents)).to be 1 }
76
+ it { expect(subject.call(1.70 , type: :cents)).to be 1.70 }
77
+ it { expect(subject.call(103.70 , type: :cents)).to be 103.70 }
78
+ it { expect(subject.call(1030.70 , type: :cents)).to be 1030.70 }
79
+ it { expect(subject.call(10_300.70, type: :cents)).to be 10_300.70 }
80
+
81
+ context 'with two decimal precision' do
82
+ it { expect(subject.call('1.70' , type: :cents)).to eq '170' }
83
+ it { expect(subject.call('103.70' , type: :cents)).to eq '10370' }
84
+ it { expect(subject.call('1030.70' , type: :cents)).to eq '103070' }
85
+ it { expect(subject.call('10300.70', type: :cents)).to eq '1030070' }
86
+
87
+ it { expect(subject.call('1 %' , type: :cents)).to eq '100' }
88
+ it { expect(subject.call('1.70 %' , type: :cents)).to eq '170' }
89
+ it { expect(subject.call('103.70 %' , type: :cents)).to eq '10370' }
90
+ it { expect(subject.call('1030.70 %' , type: :cents)).to eq '103070' }
91
+ it { expect(subject.call('10300.70 %', type: :cents)).to eq '1030070' }
92
+
93
+ context 'with :cast' do
94
+ it { expect(subject.call('1.70' , cast: :to_f, type: :cents)).to be 170.0 }
95
+ it { expect(subject.call('103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
96
+ it { expect(subject.call('1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
97
+ it { expect(subject.call('10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
98
+
99
+ it { expect(subject.call('1 %' , cast: :to_f, type: :cents)).to be 100.0 }
100
+ it { expect(subject.call('1.70 %' , cast: :to_f, type: :cents)).to be 170.0 }
101
+ it { expect(subject.call('103.70 %' , cast: :to_f, type: :cents)).to be 10_370.0 }
102
+ it { expect(subject.call('1030.70 %' , cast: :to_f, type: :cents)).to be 103_070.0 }
103
+ it { expect(subject.call('10300.70 %', cast: :to_f, type: :cents)).to be 1_030_070.0 }
104
+ end
105
+ end
106
+
107
+ context 'with one decimal precision' do
108
+ it { expect(subject.call('1.7' , type: :cents)).to eq '170' }
109
+ it { expect(subject.call('103.7' , type: :cents)).to eq '10370' }
110
+ it { expect(subject.call('1030.7' , type: :cents)).to eq '103070' }
111
+ it { expect(subject.call('10300.7', type: :cents)).to eq '1030070' }
112
+
113
+ it { expect(subject.call('1.7 %' , type: :cents)).to eq '170' }
114
+ it { expect(subject.call('103.7 %' , type: :cents)).to eq '10370' }
115
+ it { expect(subject.call('1030.7 %' , type: :cents)).to eq '103070' }
116
+ it { expect(subject.call('10300.7 %', type: :cents)).to eq '1030070' }
117
+
118
+ context 'with :cast' do
119
+ it { expect(subject.call('1.7' , cast: :to_f, type: :cents)).to be 170.0 }
120
+ it { expect(subject.call('103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
121
+ it { expect(subject.call('1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
122
+ it { expect(subject.call('10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
123
+
124
+ it { expect(subject.call('1.7 %' , cast: :to_f, type: :cents)).to be 170.0 }
125
+ it { expect(subject.call('103.7 %' , cast: :to_f, type: :cents)).to be 10_370.0 }
126
+ it { expect(subject.call('1030.7 %' , cast: :to_f, type: :cents)).to be 103_070.0 }
127
+ it { expect(subject.call('10300.7 %', cast: :to_f, type: :cents)).to be 1_030_070.0 }
128
+ end
129
+ end
130
+
131
+ context 'with no decimal precision' do
132
+ it { expect(subject.call('1', type: :cents)).to eq '100' }
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'with :separator options' do
138
+ context 'provided via options rule' do
139
+ it { expect(subject.call('1-2', separator: '-')).to eq '1.20' }
140
+ end
141
+
142
+ context 'provided I18n' do
143
+ before do
144
+ allow(I18n).to receive(:t).with('percentage.format.separator', default: '.') { 'x' }
145
+ allow(I18n).to receive(:t).with('percentage.format.precision', default: 2) { 2 }
146
+ end
147
+
148
+ it { expect(subject.call('1x2')).to eq '1.20' }
149
+ end
150
+
151
+ context 'when not provided' do
152
+ it { expect(subject.call('1.2')).to eq '1.20' }
153
+ end
154
+ end
155
+ end
data/spec/rails_helper.rb CHANGED
@@ -7,3 +7,7 @@ require 'normalizy'
7
7
  require 'pry-byebug'
8
8
 
9
9
  Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
10
+
11
+ def offset_in_hours(time_zone)
12
+ TZInfo::Timezone.get(time_zone).current_period.offset.utc_total_offset.to_f / 3600.0
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
2
4
 
3
5
  ActiveRecord::Schema.define(version: 0) do
@@ -6,8 +8,11 @@ ActiveRecord::Schema.define(version: 0) do
6
8
  end
7
9
 
8
10
  create_table :users do |t|
9
- t.integer :age
10
- t.integer :amount
11
- t.string :name
11
+ t.datetime :birthday
12
+ t.decimal :amount, precision: 16, scale: 10
13
+ t.integer :age
14
+ t.integer :amount_cents
15
+ t.string :amount_text
16
+ t.string :name
12
17
  end
13
18
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Normalizy
4
+ module Filters
5
+ module Blacklist1
6
+ def self.call(input)
7
+ input.gsub 'Fuck', 'filtered'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Normalizy
4
+ module Filters
5
+ module Blacklist2
6
+ def self.call(_input, options = {})
7
+ attribute = options[:attribute]
8
+
9
+ "#{attribute}: #{options[:object].send(attribute)}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Normalizy
4
+ module Filters
5
+ module BlacklistBlock
6
+ def self.call(input)
7
+ yield input
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,6 +4,6 @@ class User < ActiveRecord::Base
4
4
  normalizy :name
5
5
 
6
6
  def custom_reverse(input, options = {})
7
- "#{input.reverse}.#{options}.custom"
7
+ "'#{input.reverse}' to '#{options[:object].name}'"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: normalizy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -129,7 +129,10 @@ files:
129
129
  - lib/normalizy/config.rb
130
130
  - lib/normalizy/extensions.rb
131
131
  - lib/normalizy/filters.rb
132
+ - lib/normalizy/filters/date.rb
133
+ - lib/normalizy/filters/money.rb
132
134
  - lib/normalizy/filters/number.rb
135
+ - lib/normalizy/filters/percent.rb
133
136
  - lib/normalizy/filters/strip.rb
134
137
  - lib/normalizy/rspec/matcher.rb
135
138
  - lib/normalizy/version.rb
@@ -139,10 +142,17 @@ files:
139
142
  - spec/normalizy/config/initialize_spec.rb
140
143
  - spec/normalizy/config/normalizy_aliases_spec.rb
141
144
  - spec/normalizy/config/normalizy_raws_spec.rb
142
- - spec/normalizy/extensions/apply_normalizations_spec.rb
145
+ - spec/normalizy/extensions/apply_normalizy_spec.rb
146
+ - spec/normalizy/extensions/filters/date_spec.rb
147
+ - spec/normalizy/extensions/filters/money_spec.rb
148
+ - spec/normalizy/extensions/filters/number_spec.rb
149
+ - spec/normalizy/extensions/filters/percent_spec.rb
150
+ - spec/normalizy/extensions/filters/strip_spec.rb
143
151
  - spec/normalizy/extensions/normalizy_rules_spec.rb
144
- - spec/normalizy/extensions/normalizy_spec.rb
152
+ - spec/normalizy/filters/date_spec.rb
153
+ - spec/normalizy/filters/money_spec.rb
145
154
  - spec/normalizy/filters/number_spec.rb
155
+ - spec/normalizy/filters/percent_spec.rb
146
156
  - spec/normalizy/filters/strip_spec.rb
147
157
  - spec/normalizy/normalizy/configure_spec.rb
148
158
  - spec/normalizy/rspec/matcher/description_spec.rb
@@ -155,7 +165,9 @@ files:
155
165
  - spec/rails_helper.rb
156
166
  - spec/support/common.rb
157
167
  - spec/support/db/schema.rb
158
- - spec/support/filters/blacklist_filter.rb
168
+ - spec/support/filters/blacklist_1.rb
169
+ - spec/support/filters/blacklist_2.rb
170
+ - spec/support/filters/blacklist_block.rb
159
171
  - spec/support/models/clean.rb
160
172
  - spec/support/models/user.rb
161
173
  homepage: https://github.com/wbotelhos/normalizy
@@ -189,10 +201,17 @@ test_files:
189
201
  - spec/normalizy/config/initialize_spec.rb
190
202
  - spec/normalizy/config/normalizy_aliases_spec.rb
191
203
  - spec/normalizy/config/normalizy_raws_spec.rb
192
- - spec/normalizy/extensions/apply_normalizations_spec.rb
204
+ - spec/normalizy/extensions/apply_normalizy_spec.rb
205
+ - spec/normalizy/extensions/filters/date_spec.rb
206
+ - spec/normalizy/extensions/filters/money_spec.rb
207
+ - spec/normalizy/extensions/filters/number_spec.rb
208
+ - spec/normalizy/extensions/filters/percent_spec.rb
209
+ - spec/normalizy/extensions/filters/strip_spec.rb
193
210
  - spec/normalizy/extensions/normalizy_rules_spec.rb
194
- - spec/normalizy/extensions/normalizy_spec.rb
211
+ - spec/normalizy/filters/date_spec.rb
212
+ - spec/normalizy/filters/money_spec.rb
195
213
  - spec/normalizy/filters/number_spec.rb
214
+ - spec/normalizy/filters/percent_spec.rb
196
215
  - spec/normalizy/filters/strip_spec.rb
197
216
  - spec/normalizy/normalizy/configure_spec.rb
198
217
  - spec/normalizy/rspec/matcher/description_spec.rb
@@ -205,6 +224,8 @@ test_files:
205
224
  - spec/rails_helper.rb
206
225
  - spec/support/common.rb
207
226
  - spec/support/db/schema.rb
208
- - spec/support/filters/blacklist_filter.rb
227
+ - spec/support/filters/blacklist_1.rb
228
+ - spec/support/filters/blacklist_2.rb
229
+ - spec/support/filters/blacklist_block.rb
209
230
  - spec/support/models/clean.rb
210
231
  - spec/support/models/user.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe User, 'active_record' do
6
- xit 'norm the object' do
7
- matcher.matches?(object)
8
-
9
- expect(matcher.instance_variable_get(:@subject)).to eq object
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Blacklist
6
- def self.call(input)
7
- value = input.gsub('Fuck', 'filtered')
8
-
9
- value = yield(value) if block_given?
10
-
11
- value
12
- end
13
- end
14
- end
15
- end