normalizy 1.3.0 → 1.6.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -24
  3. data/README.md +22 -16
  4. data/lib/normalizy/filters/date.rb +2 -4
  5. data/lib/normalizy/filters/money.rb +2 -2
  6. data/lib/normalizy/filters/percent.rb +2 -2
  7. data/lib/normalizy/version.rb +1 -1
  8. metadata +27 -94
  9. data/spec/normalizy/config/add_spec.rb +0 -21
  10. data/spec/normalizy/config/alias_spec.rb +0 -29
  11. data/spec/normalizy/config/default_filters_spec.rb +0 -19
  12. data/spec/normalizy/config/initialize_spec.rb +0 -16
  13. data/spec/normalizy/config/normalizy_aliases_spec.rb +0 -9
  14. data/spec/normalizy/extensions/filters/date_spec.rb +0 -24
  15. data/spec/normalizy/extensions/filters/money_spec.rb +0 -38
  16. data/spec/normalizy/extensions/filters/number_spec.rb +0 -9
  17. data/spec/normalizy/extensions/filters/percent_spec.rb +0 -30
  18. data/spec/normalizy/extensions/filters/slug_spec.rb +0 -14
  19. data/spec/normalizy/extensions/filters/strip_spec.rb +0 -21
  20. data/spec/normalizy/extensions/model_spec.rb +0 -107
  21. data/spec/normalizy/extensions/normalizy_rules_spec.rb +0 -198
  22. data/spec/normalizy/filters/date_spec.rb +0 -50
  23. data/spec/normalizy/filters/money_spec.rb +0 -282
  24. data/spec/normalizy/filters/number_spec.rb +0 -33
  25. data/spec/normalizy/filters/percent_spec.rb +0 -168
  26. data/spec/normalizy/filters/slug_spec.rb +0 -24
  27. data/spec/normalizy/filters/strip_spec.rb +0 -13
  28. data/spec/normalizy/normalizy/configure_spec.rb +0 -11
  29. data/spec/normalizy/rspec/matcher/description_spec.rb +0 -27
  30. data/spec/normalizy/rspec/matcher/failure_message_spec.rb +0 -48
  31. data/spec/normalizy/rspec/matcher/failure_message_when_negated_spec.rb +0 -30
  32. data/spec/normalizy/rspec/matcher/from_spec.rb +0 -19
  33. data/spec/normalizy/rspec/matcher/matches_spec.rb +0 -117
  34. data/spec/normalizy/rspec/matcher/to_spec.rb +0 -19
  35. data/spec/rails_helper.rb +0 -9
  36. data/spec/support/common.rb +0 -11
  37. data/spec/support/db/schema.rb +0 -81
  38. data/spec/support/filters/blacklist.rb +0 -11
  39. data/spec/support/filters/block.rb +0 -11
  40. data/spec/support/filters/info.rb +0 -11
  41. data/spec/support/models/alias.rb +0 -7
  42. data/spec/support/models/match.rb +0 -9
  43. data/spec/support/models/model.rb +0 -28
  44. data/spec/support/models/model_date.rb +0 -7
  45. data/spec/support/models/model_money.rb +0 -10
  46. data/spec/support/models/model_number.rb +0 -5
  47. data/spec/support/models/model_percent.rb +0 -10
  48. data/spec/support/models/model_slug.rb +0 -6
  49. data/spec/support/models/model_strip.rb +0 -8
  50. data/spec/support/models/rule.rb +0 -4
@@ -1,168 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Percent do
6
- describe '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('100')).to eq '100.00' }
17
- it { expect(subject.call('100.0')).to eq '100.00' }
18
- it { expect(subject.call('1.70')).to eq '1.70' }
19
- it { expect(subject.call('103.70')).to eq '103.70' }
20
- it { expect(subject.call('1030.70')).to eq '1030.70' }
21
- it { expect(subject.call('10300.70')).to eq '10300.70' }
22
-
23
- it { expect(subject.call('$ 0.01')).to eq '0.01' }
24
- it { expect(subject.call('$ 1')).to eq '1.00' }
25
- it { expect(subject.call('$ 1.70')).to eq '1.70' }
26
- it { expect(subject.call('$ 103.70')).to eq '103.70' }
27
- it { expect(subject.call('$ 1030.70')).to eq '1030.70' }
28
- it { expect(subject.call('$ 10300.70')).to eq '10300.70' }
29
- end
30
-
31
- describe 'type' do
32
- it { expect(subject.call('', type: :cents)).to eq nil }
33
-
34
- it { expect(subject.call(1 , type: :cents)).to be 1 }
35
- it { expect(subject.call(1.70 , type: :cents)).to be 1.70 }
36
- it { expect(subject.call(103.70 , type: :cents)).to be 103.70 }
37
- it { expect(subject.call(1030.70 , type: :cents)).to be 1030.70 }
38
- it { expect(subject.call(10_300.70, type: :cents)).to be 10_300.70 }
39
-
40
- context 'with different separator' do
41
- it { expect(subject.call('1,7', separator: ',', type: :cents)).to eq '170' }
42
- end
43
-
44
- context 'with no decimal precision' do
45
- it { expect(subject.call('1' , type: :cents)).to eq '1' }
46
- it { expect(subject.call('10' , type: :cents)).to eq '10' }
47
- it { expect(subject.call('100', type: :cents)).to eq '100' }
48
-
49
- context 'with float :cast' do
50
- it { expect(subject.call('1' , cast: :to_f, type: :cents)).to eq 1.0 }
51
- it { expect(subject.call('10' , cast: :to_f, type: :cents)).to eq 10.0 }
52
- it { expect(subject.call('100', cast: :to_f, type: :cents)).to eq 100.0 }
53
- end
54
- end
55
-
56
- context 'with one decimal precision' do
57
- it { expect(subject.call('1.7' , type: :cents)).to eq '170' }
58
- it { expect(subject.call('103.7' , type: :cents)).to eq '10370' }
59
- it { expect(subject.call('1030.7' , type: :cents)).to eq '103070' }
60
- it { expect(subject.call('10300.7', type: :cents)).to eq '1030070' }
61
-
62
- it { expect(subject.call('$ 1.7' , type: :cents)).to eq '170' }
63
- it { expect(subject.call('$ 103.7' , type: :cents)).to eq '10370' }
64
- it { expect(subject.call('$ 1030.7' , type: :cents)).to eq '103070' }
65
- it { expect(subject.call('$ 10300.7', type: :cents)).to eq '1030070' }
66
-
67
- context 'with float :cast' do
68
- it { expect(subject.call('1.7' , cast: :to_f, type: :cents)).to be 170.0 }
69
- it { expect(subject.call('103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
70
- it { expect(subject.call('1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
71
- it { expect(subject.call('10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
72
-
73
- it { expect(subject.call('$ 1.7' , cast: :to_f, type: :cents)).to be 170.0 }
74
- it { expect(subject.call('$ 103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
75
- it { expect(subject.call('$ 1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
76
- it { expect(subject.call('$ 10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
77
- end
78
- end
79
-
80
- context 'with two decimal precision' do
81
- it { expect(subject.call('1.70' , type: :cents)).to eq '170' }
82
- it { expect(subject.call('103.70' , type: :cents)).to eq '10370' }
83
- it { expect(subject.call('1030.70' , type: :cents)).to eq '103070' }
84
- it { expect(subject.call('10300.70', type: :cents)).to eq '1030070' }
85
-
86
- it { expect(subject.call('$ 1.70' , type: :cents)).to eq '170' }
87
- it { expect(subject.call('$ 103.70' , type: :cents)).to eq '10370' }
88
- it { expect(subject.call('$ 1030.70' , type: :cents)).to eq '103070' }
89
- it { expect(subject.call('$ 10300.70', type: :cents)).to eq '1030070' }
90
-
91
- context 'with float :cast' do
92
- it { expect(subject.call('1.70' , cast: :to_f, type: :cents)).to be 170.0 }
93
- it { expect(subject.call('103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
94
- it { expect(subject.call('1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
95
- it { expect(subject.call('10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
96
-
97
- it { expect(subject.call('$ 1.70' , cast: :to_f, type: :cents)).to be 170.0 }
98
- it { expect(subject.call('$ 103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
99
- it { expect(subject.call('$ 1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
100
- it { expect(subject.call('$ 10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
101
- end
102
- end
103
- end
104
-
105
- describe 'separator' do
106
- context 'when provided inline' do
107
- it { expect(subject.call('R$ 0,01', separator: ',')).to eq '0.01' }
108
- end
109
-
110
- context 'when provided I18n' do
111
- before do
112
- allow(I18n).to receive(:t).with('percentage.format.separator', default: '.').and_return 'x'
113
- allow(I18n).to receive(:t).with('percentage.format.precision', default: 2).and_return 2
114
- end
115
-
116
- it { expect(subject.call('1x2')).to eq '1.20' }
117
- end
118
-
119
- context 'when not provided' do
120
- it { expect(subject.call('1.2')).to eq '1.20' }
121
- end
122
- end
123
-
124
- describe 'cast' do
125
- context 'with no decimal precision' do
126
- it { expect(subject.call('1' , cast: :to_f)).to eq 1.0 }
127
- it { expect(subject.call('10' , cast: :to_f)).to eq 10.0 }
128
- it { expect(subject.call('100', cast: :to_f)).to eq 100.0 }
129
- end
130
-
131
- context 'when value has one decimal precision' do
132
- it { expect(subject.call('1.7' , cast: :to_f)).to eq 1.7 }
133
- it { expect(subject.call('103.7' , cast: :to_f)).to eq 103.7 }
134
- it { expect(subject.call('1030.7' , cast: :to_f)).to eq 1030.7 }
135
- it { expect(subject.call('10300.7', cast: :to_f)).to eq 10_300.7 }
136
-
137
- it { expect(subject.call('$ 1.7' , cast: :to_f)).to eq 1.7 }
138
- it { expect(subject.call('$ 103.7' , cast: :to_f)).to eq 103.7 }
139
- it { expect(subject.call('$ 1030.7' , cast: :to_f)).to eq 1030.7 }
140
- it { expect(subject.call('$ 10300.7', cast: :to_f)).to eq 10_300.7 }
141
-
142
- context 'with calls cast' do
143
- it { expect(subject.call('1.7' , cast: :to_f)).to be 1.7 }
144
- it { expect(subject.call('103.7' , cast: :to_f)).to be 103.7 }
145
- it { expect(subject.call('1030.7' , cast: :to_f)).to be 1030.7 }
146
- it { expect(subject.call('10300.7', cast: :to_f)).to be 10_300.7 }
147
-
148
- it { expect(subject.call('$ 1.7' , cast: :to_f)).to be 1.7 }
149
- it { expect(subject.call('$ 103.7' , cast: :to_f)).to be 103.7 }
150
- it { expect(subject.call('$ 1030.7' , cast: :to_f)).to be 1030.7 }
151
- it { expect(subject.call('$ 10300.7', cast: :to_f)).to be 10_300.7 }
152
- end
153
- end
154
-
155
- context 'when value has two decimal precision' do
156
- it { expect(subject.call('1.70' , cast: :to_f)).to be 1.7 }
157
- it { expect(subject.call('103.70' , cast: :to_f)).to be 103.7 }
158
- it { expect(subject.call('1030.70' , cast: :to_f)).to be 1030.7 }
159
- it { expect(subject.call('10300.70', cast: :to_f)).to be 10_300.7 }
160
-
161
- it { expect(subject.call('$ 1' , cast: :to_f)).to be 1.0 }
162
- it { expect(subject.call('$ 1.70' , cast: :to_f)).to be 1.7 }
163
- it { expect(subject.call('$ 103.70' , cast: :to_f)).to be 103.7 }
164
- it { expect(subject.call('$ 1030.70' , cast: :to_f)).to be 1030.7 }
165
- it { expect(subject.call('$ 10300.70', cast: :to_f)).to be 10_300.7 }
166
- end
167
- end
168
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Slug do
6
- describe 'default options' do
7
- it { expect(subject.call(nil)).to eq nil }
8
- it { expect(subject.call('')).to eq '' }
9
-
10
- it { expect(subject.call('The Title')).to eq 'the-title' }
11
- end
12
-
13
- describe 'to' do
14
- it { expect(subject.call(nil , to: :slug)).to eq nil }
15
- it { expect(subject.call('' , to: :slug)).to eq '' }
16
- it { expect(subject.call('The Title', to: :slug)).to eq 'the-title' }
17
-
18
- context 'when is not :to key' do
19
- it { expect(subject.call(nil , from: :slug)).to eq nil }
20
- it { expect(subject.call('' , from: :slug)).to eq '' }
21
- it { expect(subject.call('The Title', from: :slug)).to eq 'the-title' }
22
- end
23
- end
24
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Strip do
6
- it { expect(subject.call(' Some Text ')).to eq 'Some Text' }
7
- it { expect(subject.call(' Some Text ', side: :left)).to eq 'Some Text ' }
8
- it { expect(subject.call(' Some Text ', side: :right)).to eq ' Some Text' }
9
- it { expect(subject.call(' Some Text ', side: :both)).to eq 'Some Text' }
10
- it { expect(subject.call("\n")).to eq '' }
11
- it { expect(subject.call(42)).to eq 42 }
12
- it { expect(subject.call(nil)).to eq nil }
13
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy, '#configure' do
6
- it 'yields the default config' do
7
- described_class.configure do |conf|
8
- expect(conf).to be_a_instance_of Normalizy::Config
9
- end
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.description' do
6
- let!(:matcher) { described_class.new :name }
7
-
8
- context 'with no :with expectation' do
9
- it do
10
- matcher.from :from
11
- matcher.to :to
12
-
13
- expect(matcher.description).to eq 'normalizy name from "from" to "to"'
14
- end
15
- end
16
-
17
- context 'with :with expectation' do
18
- it do
19
- matcher.with :blank
20
-
21
- matcher.from :from
22
- matcher.to :to
23
-
24
- expect(matcher.description).to eq 'normalizy name with blank'
25
- end
26
- end
27
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.failure_message' do
6
- let!(:model) { Match }
7
-
8
- context 'with no :with expectation' do
9
- it do
10
- matcher = described_class.new(:downcase_field)
11
-
12
- matcher.from :from
13
- matcher.to :to
14
- matcher.matches? model.new
15
-
16
- expect(matcher.failure_message).to eq %(expected: "to"\n got: "from")
17
- end
18
- end
19
-
20
- context 'with :with expectation' do
21
- it do
22
- matcher = described_class.new(:alone)
23
-
24
- matcher.with :missing
25
- matcher.matches? model.new
26
-
27
- expect(matcher.failure_message).to eq %(expected: missing\n got: nil)
28
- end
29
-
30
- it do
31
- matcher = described_class.new(:downcase_field_array)
32
-
33
- matcher.with :missing
34
- matcher.matches? model.new
35
-
36
- expect(matcher.failure_message).to eq %(expected: missing\n got: downcase)
37
- end
38
-
39
- it do
40
- matcher = described_class.new(:trim_side_left)
41
-
42
- matcher.with :missing
43
- matcher.matches? model.new
44
-
45
- expect(matcher.failure_message).to eq %(expected: missing\n got: {:trim=>{:side=>:left}})
46
- end
47
- end
48
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.failure_message_when_negated' do
6
- let!(:model) { Match }
7
-
8
- context 'with no :with expectation' do
9
- it do
10
- matcher = described_class.new(:downcase_field)
11
-
12
- matcher.from 'from'
13
- matcher.to 'from'
14
- matcher.matches? model.new
15
-
16
- expect(matcher.failure_message_when_negated).to eq %(expected: value != "from"\n got: "from")
17
- end
18
- end
19
-
20
- context 'with :with expectation' do
21
- it do
22
- matcher = described_class.new(:downcase_field)
23
-
24
- matcher.with :downcase
25
- matcher.matches? model.new
26
-
27
- expect(matcher.failure_message_when_negated).to eq %(expected: value != downcase\n got: downcase)
28
- end
29
- end
30
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.from' do
6
- it 'caches the value' do
7
- matcher = described_class.new(:downcase_field)
8
-
9
- matcher.from :from
10
-
11
- expect(matcher.instance_variable_get(:@from)).to eq :from
12
- end
13
-
14
- it 'returns it self' do
15
- matcher = described_class.new(:downcase_field)
16
-
17
- expect(matcher.from(:from)).to be matcher
18
- end
19
- end
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.matches?' do
6
- let!(:object) { Match.new }
7
-
8
- it do
9
- matcher = described_class.new(:alone)
10
-
11
- matcher.matches?(object)
12
-
13
- expect(matcher.instance_variable_get(:@subject)).to eq object
14
- end
15
-
16
- context 'when .with is called' do
17
- it do
18
- matcher = described_class.new(:alone)
19
-
20
- matcher.with :missing
21
-
22
- expect(matcher.matches?(object)).to eq false
23
- end
24
-
25
- it do
26
- matcher = described_class.new(:downcase_field)
27
-
28
- matcher.with :downcase
29
-
30
- expect(matcher.matches?(object)).to eq true
31
- end
32
-
33
- it do
34
- matcher = described_class.new(:trim_side_left)
35
-
36
- matcher.with trim: { side: :left }
37
-
38
- expect(matcher.matches?(object)).to eq true
39
- end
40
-
41
- it do
42
- matcher = described_class.new(:trim_side_left_array)
43
-
44
- matcher.with trim: { side: :left }
45
-
46
- expect(matcher.matches?(object)).to eq true
47
- end
48
-
49
- it do
50
- Normalizy.configure do |config|
51
- config.default_filters = :squish
52
- end
53
-
54
- matcher = described_class.new(:alone)
55
-
56
- matcher.with :squish
57
-
58
- expect(matcher.matches?(object)).to eq true
59
- end
60
-
61
- it do
62
- Normalizy.configure do |config|
63
- config.default_filters = [:squish]
64
- end
65
-
66
- matcher = described_class.new(:alone)
67
-
68
- matcher.with :squish
69
-
70
- expect(matcher.matches?(object)).to eq true
71
- end
72
-
73
- it do
74
- Normalizy.configure do |config|
75
- config.default_filters = [{ strip: { side: :left } }]
76
- end
77
-
78
- matcher = described_class.new(:alone)
79
-
80
- matcher.with(strip: { side: :left })
81
-
82
- expect(matcher.matches?(object)).to eq true
83
- end
84
-
85
- it do
86
- Normalizy.configure do |config|
87
- config.default_filters = :squish
88
- end
89
-
90
- matcher = described_class.new(:downcase_field)
91
-
92
- matcher.with :squish
93
-
94
- expect(matcher.matches?(object)).to eq false
95
- end
96
- end
97
-
98
- context 'when .with is not called' do
99
- it do
100
- matcher = described_class.new(:alone)
101
-
102
- matcher.from '1'
103
- matcher.to '2'
104
-
105
- expect(matcher.matches?(object)).to eq false
106
- end
107
-
108
- it do
109
- matcher = described_class.new(:downcase_field)
110
-
111
- matcher.from 'BOTELHO'
112
- matcher.to 'botelho'
113
-
114
- expect(matcher.matches?(object)).to eq true
115
- end
116
- end
117
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.to' do
6
- it 'caches the value' do
7
- matcher = described_class.new(:downcase)
8
-
9
- matcher.to :to
10
-
11
- expect(matcher.instance_variable_get(:@to)).to eq :to
12
- end
13
-
14
- it 'returns it self' do
15
- matcher = described_class.new(:downcase)
16
-
17
- expect(matcher.to(:to)).to be matcher
18
- end
19
- end
data/spec/rails_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ENV['RAILS_ENV'] ||= 'test'
4
-
5
- require 'active_record/railtie'
6
- require 'normalizy'
7
- require 'pry-byebug'
8
-
9
- Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rspec/rails'
4
-
5
- RSpec.configure do |config|
6
- config.filter_run_when_matching :focus
7
-
8
- config.disable_monkey_patching!
9
-
10
- config.order = :random
11
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
4
-
5
- ActiveRecord::Schema.define(version: 0) do
6
- create_table :aliases do |t|
7
- t.string :email
8
- t.string :with_arg_field
9
- t.string :with_inline_arg_field
10
- end
11
-
12
- create_table :matches do |t|
13
- t.string :alone
14
- t.string :downcase_field
15
- t.string :trim_side_left
16
- t.string :downcase_field_array
17
- end
18
-
19
- create_table :models do |t|
20
- t.string :none
21
- t.string :default
22
- t.string :block
23
- t.string :symbol
24
- t.string :array_symbol
25
- t.string :array_symbols
26
- t.string :hash_no_args
27
- t.string :hash_with_args
28
- t.string :module_one_arg
29
- t.string :module_two_args
30
- t.string :module_and_block
31
- t.string :method_with_no_options_field
32
- t.string :method_with_options_field
33
- t.string :native
34
- t.string :multiple
35
- end
36
-
37
- create_table :model_dates do |t|
38
- t.datetime :date
39
- t.datetime :date_format
40
- t.datetime :date_time_zone
41
- end
42
-
43
- create_table :model_moneys do |t|
44
- t.string :text
45
- t.string :cents_type
46
- t.integer :cast_to_i
47
- t.decimal :cast_to_d
48
- t.float :cents_type_and_cast_to_f
49
- t.integer :cents_type_and_cast_to_i
50
- end
51
-
52
- create_table :model_numbers do |t|
53
- t.string :number
54
- end
55
-
56
- create_table :model_percents do |t|
57
- t.string :text
58
- t.string :cents_type
59
- t.integer :cast_to_i
60
- t.decimal :cast_to_d
61
- t.float :cents_type_and_cast_to_f
62
- t.integer :cents_type_and_cast_to_i
63
- end
64
-
65
- create_table :model_slugs do |t|
66
- t.string :permalink
67
- t.string :slug
68
- t.string :title
69
- end
70
-
71
- create_table :model_strips do |t|
72
- t.string :strip
73
- t.string :strip_side_both
74
- t.string :strip_side_left
75
- t.string :strip_side_right
76
- end
77
-
78
- create_table :rules do |t|
79
- t.string :name
80
- end
81
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Blacklist
6
- def self.call(input)
7
- input.gsub 'Fuck', 'filtered'
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Block
6
- def self.call(input)
7
- yield input
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Info
6
- def self.call(input, options = {})
7
- [options[:attribute], input, options[:object].class].join ', '
8
- end
9
- end
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Alias < ActiveRecord::Base
4
- normalizy :email , with: :email
5
- normalizy :with_arg_field , with: :with_arg
6
- normalizy :with_inline_arg_field, with: { with_inline_arg: { side: :left } }
7
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Match < ActiveRecord::Base
4
- normalizy :alone
5
- normalizy :downcase_field , with: :downcase
6
- normalizy :trim_side_left , with: { trim: { side: :left } }
7
- normalizy :trim_side_left_array, with: [{ trim: { side: :left } }]
8
- normalizy :downcase_field_array, with: [:downcase]
9
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Model < ActiveRecord::Base
4
- normalizy :default
5
-
6
- normalizy :block , with: ->(value) { value.upcase }
7
- normalizy :symbol , with: :squish
8
- normalizy :array_symbol , with: [:squish]
9
- normalizy :array_symbols , with: %i[downcase squish]
10
- normalizy :hash_no_args , with: { squish: { ignored: true } }
11
- normalizy :hash_with_args , with: { strip: { side: :left } }
12
- normalizy :module_one_arg , with: Normalizy::Filters::Blacklist
13
- normalizy :module_two_args , with: Normalizy::Filters::Info
14
- normalizy :module_and_block , with: :blacklist, &->(value) { value.upcase }
15
- normalizy :method_with_no_options_field, with: :method_with_no_options
16
- normalizy :method_with_options_field , with: { method_with_options: { key: :value } }
17
- normalizy :native , with: :split
18
- normalizy :multiple , with: :downcase
19
- normalizy :multiple , with: :titleize
20
-
21
- def method_with_options(input, options = {})
22
- [input, options].join ', '
23
- end
24
-
25
- def method_with_no_options(input)
26
- input
27
- end
28
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ModelDate < ActiveRecord::Base
4
- normalizy :date , with: :date
5
- normalizy :date_format , with: { date: { format: '%y/%m/%d' } }
6
- normalizy :date_time_zone, with: { date: { time_zone: 'Brasilia' } }
7
- end