normalizy 1.6.0 → 1.7.0

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: 0ce6511269094da3b936369b12195ad147ecbc4a67be1649eedf4a96a18aba63
4
- data.tar.gz: bc8454295d05564e66a702d528132487297a0b969a62b56a182cc33e27156747
3
+ metadata.gz: ee7f65965cec5c289729431b01fcf23be051784ec7b18bf9b71ae00c698d9d93
4
+ data.tar.gz: ad9ce5473030dec2eae92783feecf6895e8e5e841bee48b5af46f4b6579dcc12
5
5
  SHA512:
6
- metadata.gz: 197c6dc140be871e4758e67e8197ab55015760ec711c54f9923783bd516d79d084a8d13fe39fd6ff582cf634796b533938adfc7d437257d4f8a96ee02f926f5e
7
- data.tar.gz: 36b8f76aa291b2bd977902777518e8c48ca4a6f7be5ab224d17e3de33c04cd1d02fdca9387dcf7ffeab83fc08ebc2f2e657a99fccaa169d6713cad67d236ea46
6
+ metadata.gz: c2c043c42e3627fb56b02defc6a0081311da5b72dfb1da0ecda255abca81a734b4a47c4c25054f24d5c4dec75059862fa250482e54d84f79a6905ecde4e5a7cc
7
+ data.tar.gz: eec956c476590a3a521f33ed58e657add31f52d391cb29362856d9dce14968f8d55df4f38b7d030071283da2d236ee1ec87654c5b6598a181ea45c227ef32216
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v1.7.0
2
+
3
+ ### Features
4
+
5
+ - Adds `truncate` filter; [#3](https://github.com/wbotelhos/normalizy/pull/3) by [rafaeldev](https://github.com/rafaeldev)
6
+
7
+ ### Updates
8
+
9
+ - Adds RuboCop task on the CI;
10
+
1
11
  ## v1.6.0
2
12
 
3
13
  ### Fixes
@@ -9,13 +19,13 @@
9
19
  - Adds Code Quality;
10
20
  - Adds Test Coverage;
11
21
  - Migrates the build to Github Actions;
12
- - Removes Git dependency for build;
22
+ - Removes Git dependency for the build;
13
23
 
14
24
  ## v1.5.0
15
25
 
16
26
  ### Features
17
27
 
18
- - Filter `date` now supports call object that respond to `beginning_of_day` or `end_of_day`;
28
+ - Filter `date` now supports call object that responds to `beginning_of_day` or `end_of_day`;
19
29
 
20
30
  ## v1.4.0
21
31
 
@@ -39,19 +49,19 @@
39
49
 
40
50
  ### Fixes
41
51
 
42
- - When use `slug` filter the original values was not saved.
52
+ - When using `slug` filter the original values were not saved.
43
53
 
44
54
  ## v1.1.0
45
55
 
46
56
  ### Features
47
57
 
48
- - Added `slug` filter with option to apply the value on other field.
58
+ - Added `slug` filter with the option to apply the value on other fields.
49
59
 
50
60
  ## v1.0.1
51
61
 
52
62
  ### Fixes
53
63
 
54
- - When `type` options was `cents` and had no decimal on number, extra decimal were added.
64
+ - When `type` options were `cents` and had no decimal on the number, extra decimals were added.
55
65
 
56
66
  ## v1.0.0
57
67
 
@@ -73,7 +83,7 @@
73
83
  ### Updates
74
84
 
75
85
  - `number` filter no more make cast automatically.
76
- - `number` now accept `cast` options with method to be used on cast type;
86
+ - `number` now accept `cast` options with a method to be used on cast type;
77
87
 
78
88
  ### Features
79
89
 
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![CI](https://github.com/wbotelhos/normalizy/workflows/CI/badge.svg)](https://github.com/wbotelhos/normalizy/actions)
4
4
  [![Gem Version](https://badge.fury.io/rb/normalizy.svg)](https://badge.fury.io/rb/normalizy)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/f312587b4f126bb13e85/maintainability)](https://codeclimate.com/github/wbotelhos/normalizy/maintainability)
6
- [![Coverage](https://codecov.io/gh/wbotelhos/normalizy/branch/main/graph/badge.svg)](https://codecov.io/gh/wbotelhos/normalizy)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3896d0a11bee012c818c/maintainability)](https://codeclimate.com/github/wbotelhos/normalizy/maintainability)
6
+ [![codecov](https://codecov.io/gh/wbotelhos/normalizy/branch/master/graph/badge.svg?token=0XTRFDFHDq)](https://codecov.io/gh/wbotelhos/normalizy)
7
7
  [![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://www.patreon.com/wbotelhos)
8
8
 
9
9
  Attribute normalizer for Rails.
@@ -406,6 +406,17 @@ normalizy :name, with: { strip: { side: :both } }
406
406
 
407
407
  As you can see, the rules can be passed as Symbol/String or as Hash if it has options.
408
408
 
409
+ ### Truncate
410
+
411
+ Remove excedent string part from a gived limit.
412
+
413
+ ```ruby
414
+ normalizy :description, with: { truncate: { limit: 10 } }
415
+
416
+ 'Once upon a time in a world far far away'
417
+ # 'Once upon '
418
+ ```
419
+
409
420
  ## Multiple Filters
410
421
 
411
422
  You can normalize with a couple of filters at once:
@@ -29,7 +29,8 @@ module Normalizy
29
29
  number: Normalizy::Filters::Number,
30
30
  percent: Normalizy::Filters::Percent,
31
31
  slug: Normalizy::Filters::Slug,
32
- strip: Normalizy::Filters::Strip
32
+ strip: Normalizy::Filters::Strip,
33
+ truncate: Normalizy::Filters::Truncate,
33
34
  }
34
35
  end
35
36
  end
@@ -4,7 +4,7 @@ module Normalizy
4
4
  module Filters
5
5
  module Slug
6
6
  class << self
7
- def call(input, options = {})
7
+ def call(input, _options = {})
8
8
  return input unless input.is_a?(String)
9
9
 
10
10
  input.parameterize
@@ -9,7 +9,7 @@ module Normalizy
9
9
  regex = {
10
10
  both: '\A\s*|\s*\z',
11
11
  left: '\A\s*',
12
- right: '\s*\z'
12
+ right: '\s*\z',
13
13
  }[options[:side] || :both]
14
14
 
15
15
  input.gsub Regexp.new(/#{regex}/), ''
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Normalizy
4
+ module Filters
5
+ module Truncate
6
+ module_function
7
+
8
+ def call(input, options = {})
9
+ return input unless options[:limit].is_a?(Integer)
10
+ return input unless input.is_a?(String)
11
+
12
+ input[0, options[:limit]]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Normalizy
4
- VERSION = '1.6.0'
4
+ VERSION = '1.7.0'
5
5
  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: 1.6.0
4
+ version: 1.7.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: 2022-03-19 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry-byebug
42
+ name: debug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -146,12 +146,14 @@ files:
146
146
  - lib/normalizy/filters/percent.rb
147
147
  - lib/normalizy/filters/slug.rb
148
148
  - lib/normalizy/filters/strip.rb
149
+ - lib/normalizy/filters/truncate.rb
149
150
  - lib/normalizy/rspec/matcher.rb
150
151
  - lib/normalizy/version.rb
151
152
  homepage: https://github.com/wbotelhos/normalizy
152
153
  licenses:
153
154
  - MIT
154
- metadata: {}
155
+ metadata:
156
+ rubygems_mfa_required: 'true'
155
157
  post_install_message:
156
158
  rdoc_options: []
157
159
  require_paths:
@@ -167,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
169
  - !ruby/object:Gem::Version
168
170
  version: '0'
169
171
  requirements: []
170
- rubygems_version: 3.2.22
172
+ rubygems_version: 3.1.6
171
173
  signing_key:
172
174
  specification_version: 4
173
175
  summary: Attribute normalizer for Rails.