interage-helper 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: f36bec08df168eeccabb69cd87d305bad45202cc8cc12a9c8951df719778a57d
4
- data.tar.gz: '0278076c12790ccae34b87dfc2b9fffb4f1e9dfccf31c6700d2fe8172a8641f8'
3
+ metadata.gz: 9fa12c957f6264600a7e63ce1ed2f0751e90f3ff65d7dbef08a0b86f39c94629
4
+ data.tar.gz: 032dbb521e9ec10c5343519bf35f80fb388a31da366b89e13ef4769617896c2d
5
5
  SHA512:
6
- metadata.gz: 13a9ba7985a668808341028ee7b08266008cf57a5fd5dbea7483defb49f6c1d962ef114847967fd2af97e4b73137ab000f89364bd9eef260b819063f644d8e8e
7
- data.tar.gz: 1b4493459f432f9ac2561c893d3f9e04e9fbe7c0813d85a7d10f5cded67ae81f147052ee8420b7a026d0162586e97804992af341f23ca78627ef2add05ad821d
6
+ metadata.gz: 338b8d2ed326c26637fe024b523bc78928ccdd3c78540fc0a3ae939dff319993bc9d9581fda30963737189ca8c6faeedb10c55e30a70665aa84bdc3a36bd4ca3
7
+ data.tar.gz: a8ca9edde891c33aff13e29c04275fdba60816a77cedaa60decc4526daf26202789d8f759e4a9770157da013b972e8c822786d8cd9b3f261b16aa8d0f1566550
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- interage-helper (0.1.0)
4
+ interage-helper (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  Add this line to your application's Gemfile:
7
7
 
8
8
  ```ruby
9
- gem 'interage-helper', '~> 0.1.2'
9
+ gem 'interage-helper', '~> 0.1.4'
10
10
  ```
11
11
 
12
12
  And then execute:
@@ -65,130 +65,150 @@ FAVICON_FILE_NAME='icons/apple-touch-icon'
65
65
  #### Interage::LinkToHelper
66
66
 
67
67
  ```erb
68
- <p><%= link_to_edit edit_user_path(user) %></p>
69
- <p><%= link_to_back :back %></p>
70
- <p><%= link_to_show user_path(user) %></p>
71
- <p><%= link_to_destroy user_path(user) %></p>
72
- <p><%= link_to_new User, users_path %></p>
68
+ <%= link_to_edit edit_user_path(user) %>
69
+ <%= link_to_back :back %>
70
+ <%= link_to_show user_path(user) %>
71
+ <%= link_to_destroy user_path(user) %>
72
+ <%= link_to_new User, users_path %>
73
73
  ```
74
74
 
75
75
  #### Interage::ApplicationIconHelper
76
76
 
77
77
  ```erb
78
- <p><%= app_icon('user', class: 'text-muted') %></p>
79
- <p><%= app_icon_text('users', 'Usuários', class: 'text-muted') %></p>
78
+ <%= app_icon('user', class: 'text-muted') %>
79
+ <%= app_icon_text('users', 'Usuários', class: 'text-muted') %>
80
80
  ```
81
81
 
82
82
  #### Interage::FontAwesomeHelper
83
83
 
84
84
  ```erb
85
- <p><%= fa_icon('user', class: 'text-muted') %></p>
86
- <p><%= fa_icon_text('users', 'Usuários', class: 'text-muted') %></p>
85
+ <%= fa_icon('user', class: 'text-muted') %>
86
+ <%= fa_icon_text('users', 'Usuários', class: 'text-muted') %>
87
87
  ```
88
88
 
89
89
  #### Interage::MaterialDesignIconsHelper
90
90
 
91
91
  ```erb
92
- <p><%= md_icon('user', class: 'text-muted') %></p>
93
- <p><%= md_icon_text('users', 'Usuários', class: 'text-muted') %></p>
92
+ <%= md_icon('user', class: 'text-muted') %>
93
+ <%= md_icon_text('users', 'Usuários', class: 'text-muted') %>
94
94
  ```
95
95
 
96
96
  #### Interage::VersionHelper
97
97
 
98
98
  ```erb
99
- <p><%= app_version %></p>
100
- <p><%= app_text_version %></p>
99
+ <%= app_version %>
100
+ <%= app_text_version %>
101
101
  ```
102
102
 
103
103
  #### Interage::TranslationHelper
104
104
 
105
105
  ```erb
106
- <p><%= tm(User) %></p>
107
- <p><%= tmp(User) %></p>
108
- <p><%= ta(User, :name) %></p>
109
- <p><%= tb(false) %></p>
110
- <p><%= tb(true) %></p>
111
- <p><%= tbi(false) %></p>
112
- <p><%= tbi(true) %></p>
113
- <p><%= tbci(false) %></p>
114
- <p><%= tbci(true) %></p>
106
+ <%= tm(User) %>
107
+ <%= tmp(User) %>
108
+ <%= ta(User, :name) %>
109
+ <%= tb(false) %>
110
+ <%= tb(true) %>
111
+ <%= tbi(false) %>
112
+ <%= tbi(true) %>
113
+ <%= tbci(false) %>
114
+ <%= tbci(true) %>
115
115
  ```
116
116
 
117
117
  #### Interage::TextHelper
118
118
 
119
119
  ```erb
120
- <p><%= nl2br("Hello\nWorld") %></p>
120
+ <%= nl2br("Hello\nWorld") %>
121
121
  ```
122
122
 
123
123
  #### Interage::PhoneHelper
124
124
 
125
125
  ```erb
126
- <p><%= format_phone('81999599805') %></p>
126
+ <%= format_phone('+5581987654321') %>
127
+ <%= format_phone('5581987654321') %>
128
+ <%= format_phone('081987654321') %>
129
+ <%= format_phone('81987654321') %>
130
+ <%= format_phone('8187654321') %>
131
+ <%= format_phone('987654321') %>
132
+ <%= format_phone('98765432') %>
127
133
  ```
128
134
 
129
135
  #### Interage::PaginationHelper
130
136
 
131
137
  ```erb
132
- <p><%= pagination_links(@users) %></p>
138
+ <%= pagination_links(@users) %>
133
139
  ```
134
140
 
135
141
  #### Interage::NumberHelper
136
142
 
137
143
  ```erb
138
- <p><%= default_currency_format(10_000) %></p>
144
+ <%= default_currency_format(10.57) %>
145
+ <%= default_currency_format(100.17) %>
146
+ <%= default_currency_format(1_000) %>
147
+ <%= default_currency_format(10_000) %>
148
+ <%= default_currency_format(1_000_000) %>
139
149
  ```
140
150
 
141
151
  #### Interage::GravatarHelper
142
152
 
143
153
  ```erb
144
- <p><%= gravatar_image_tag('developer@interage.in') %></p>
154
+ <%= gravatar_image_tag(user.email) %>
145
155
  ```
146
156
 
147
157
  #### Interage::ControllerActiveHelper
148
158
 
149
159
  ```erb
150
- <p><%= menu_active('home') %></p>
151
- <p><%= current_controller?('home') %></p>
160
+ <%= current_controller?('home') %>
161
+ <%= current_controller?('docs') %>
162
+ <%= menu_class_show('docs') %>
163
+ <%= menu_active('docs') %>
164
+ <%= current_controller?('home', 'docs') %>
165
+ <%= menu_class_show('home', 'docs') %>
166
+ <%= menu_active('home', 'docs') %>
152
167
  ```
153
168
 
154
169
  #### Interage::CEPHelper
155
170
 
156
171
  ```erb
157
- <p><%= format_cep('54754195') %></p>
172
+ <%= format_cep('54754-195') %>
173
+ <%= format_cep('54754195') %>
158
174
  ```
159
175
 
160
- #### Interage::CPFCNPJHelper
176
+ #### Interage::CNPJHelper
161
177
 
162
178
  ```erb
163
- <p><%= format_cnpj('00000000000100') %></p>
164
- <p><%= format_cpf('05488608400') %></p>
179
+ <%= format_cnpj('08.475.876/0001-04') %>
180
+ <%= format_cnpj('08475876000104') %>
181
+ ```
182
+
183
+ #### Interage::CPFHelper
184
+
185
+ ```erb
186
+ <%= format_cpf('320.871.430-05') %>
187
+ <%= format_cpf('32087143005') %>
165
188
  ```
166
189
 
167
190
  #### Interage::ApplicationHelper
168
191
 
169
192
  ```erb
170
- <p><%= format_seconds(20) %></p>
171
- <p><%= app_page_title('adsdasdasd ') %></p>
172
- <p><%= admin_page_title %></p>
173
- <p><%= devise_page_title %></p>
174
- <p><%= page_title %></p>
175
- <p><%= app_name %></p>
176
- <p><%= env_name_upcase %></p>
193
+ <%= format_seconds(20) %>
194
+ <%= admin_page_title %>
195
+ <%= devise_page_title %>
196
+ <%= page_title %>
197
+ <%= app_name %>
198
+ <%= env_name_upcase %>
177
199
  ```
178
200
 
179
201
  #### Interage::BootstrapHelper
180
202
 
181
203
  ```erb
182
- <%= bootstrap_alert('users', '') %>
183
- <%= bootstrap_alert_default('users') %>
184
- <%= bootstrap_alert_info('users') %>
185
- <%= bootstrap_alert_warning('users') %>
186
- <%= bootstrap_alert_success('users') %>
187
- <%= bootstrap_alert_danger('users') %>
204
+ <%= bootstrap_alert_info('Info message') %>
205
+ <%= bootstrap_alert_warning('Warning message') %>
206
+ <%= bootstrap_alert_success('Success message') %>
207
+ <%= bootstrap_alert_danger('Danger message') %>
188
208
  <%= bootstrap_alert_not_found_male(User) %>
189
209
  <%= bootstrap_alert_not_found_female(User) %>
190
- <p><%= text_not_found_male(User) %></p>
191
- <p><%= text_not_found_female(User) %></p>
210
+ <%= text_not_found_male(User) %>
211
+ <%= text_not_found_female(User) %>
192
212
  ```
193
213
 
194
214
  ## Contributing
Binary file
@@ -5,9 +5,10 @@ module Interage
5
5
  include ::Interage::ApplicationIconHelper
6
6
  include ::Interage::BootstrapHelper
7
7
  include ::Interage::CEPHelper
8
+ include ::Interage::CNPJHelper
8
9
  include ::Interage::CocoonHelper
9
10
  include ::Interage::ControllerActiveHelper
10
- include ::Interage::CPFCNPJHelper
11
+ include ::Interage::CPFHelper
11
12
  include ::Interage::DateTimeHelper
12
13
  include ::Interage::FaviconHelper
13
14
  include ::Interage::FlashMessageHelper
@@ -27,7 +28,7 @@ module Interage
27
28
  end
28
29
 
29
30
  def app_page_title(area = '')
30
- "#{env_name_upcase}#{page_title}#{area}#{app_name}"
31
+ strip_tags "#{env_name_upcase}#{page_title}#{area}#{app_name}"
31
32
  end
32
33
 
33
34
  def admin_page_title
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'parsers/parser_cep'
4
+
3
5
  module Interage
4
6
  module CEPHelper
5
7
  def format_cep(cep)
6
- return if cep.blank?
7
-
8
- "#{cep[0, 5]}-#{cep[5, 3]}".strip
8
+ Interage::ParserCep.call(cep)
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parsers/parser_cnpj'
4
+
5
+ module Interage
6
+ module CNPJHelper
7
+ def format_cnpj(cnpj)
8
+ ParserCNPJ.call(cnpj)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parsers/parser_cpf'
4
+
5
+ module Interage
6
+ module CPFHelper
7
+ def format_cpf(cpf)
8
+ ParserCPF.call(cpf)
9
+ end
10
+ end
11
+ end
@@ -13,9 +13,10 @@ module Interage
13
13
  autoload :ApplicationIconHelper, 'interage/application_icon_helper'
14
14
  autoload :BootstrapHelper, 'interage/bootstrap_helper'
15
15
  autoload :CEPHelper, 'interage/cep_helper'
16
+ autoload :CNPJHelper, 'interage/cnpj_helper'
16
17
  autoload :CocoonHelper, 'interage/cocoon_helper'
17
18
  autoload :ControllerActiveHelper, 'interage/controller_active_helper'
18
- autoload :CPFCNPJHelper, 'interage/cpf_cnpj_helper'
19
+ autoload :CPFHelper, 'interage/cpf_helper'
19
20
  autoload :DateTimeHelper, 'interage/date_time_helper'
20
21
  autoload :FaviconHelper, 'interage/favicon_helper'
21
22
  autoload :FlashMessageHelper, 'interage/flash_message_helper'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Interage
4
4
  module Helper
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
  end
7
7
  end
@@ -5,5 +5,9 @@ module Interage
5
5
  def default_currency_format(number, precision = 2, unit = 'R$')
6
6
  number_to_currency(number, precision: precision, unit: unit)
7
7
  end
8
+
9
+ def only_numbers(number)
10
+ number.to_s.gsub(/[^0-9]/, '')
11
+ end
8
12
  end
9
13
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserCep
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZE = 8
8
+
9
+ def self.call(cep)
10
+ new(cep).perform
11
+ end
12
+
13
+ def initialize(cep)
14
+ @cep = only_numbers(cep).to_i
15
+ end
16
+
17
+ def perform
18
+ "#{digits[-8..-4]}-#{digits[-3..-1]}" if cep.positive?
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :cep
24
+
25
+ def digits
26
+ @digits ||= cep.to_s.rjust(ALLOWED_SIZE, '0')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserCNPJ
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZE = 14
8
+
9
+ def self.call(cnpj)
10
+ new(cnpj).perform
11
+ end
12
+
13
+ def initialize(cnpj)
14
+ @cnpj = only_numbers(cnpj).to_i
15
+ end
16
+
17
+ def perform
18
+ "#{prefix_cnpj}/#{sufix_cnpj}".strip if cnpj.positive?
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :cnpj
24
+
25
+ def prefix_cnpj
26
+ [digits[-14..-13], digits[-12..-10], digits[-9..-7]].join('.')
27
+ end
28
+
29
+ def sufix_cnpj
30
+ [digits[-6..-3], digits[-2..-1]].join('-')
31
+ end
32
+
33
+ def digits
34
+ @digits ||= cnpj.to_s.rjust(ALLOWED_SIZE, '0')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserCPF
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZE = 11
8
+
9
+ def self.call(cpf)
10
+ new(cpf).perform
11
+ end
12
+
13
+ def initialize(cpf)
14
+ @cpf = only_numbers(cpf).to_i
15
+ end
16
+
17
+ def perform
18
+ "#{prefix_cpf}-#{sufix_cpf}".strip if cpf.positive?
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :cpf
24
+
25
+ def prefix_cpf
26
+ [digits[-11..-9], digits[-8..-6], digits[-5..-3]].join('.')
27
+ end
28
+
29
+ def sufix_cpf
30
+ digits[-2..-1]
31
+ end
32
+
33
+ def digits
34
+ @digits ||= cpf.to_s.rjust(ALLOWED_SIZE, '0')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserPhone
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZES = [13, 11, 9, 8].freeze
8
+
9
+ def self.call(phone)
10
+ new(phone).perform
11
+ end
12
+
13
+ def initialize(phone)
14
+ @phone = only_numbers(phone).to_i.to_s
15
+ end
16
+
17
+ def perform
18
+ formatted_phone
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :phone
24
+
25
+ def formatted_phone
26
+ "#{country_code} #{ddd} #{prefix_phone}-#{sufix_phone}".strip
27
+ end
28
+
29
+ def country_code
30
+ "+#{phone[-13..-12]}" if phone[-13..-12].present?
31
+ end
32
+
33
+ def ddd
34
+ "(#{phone[-11..-10]})" if phone[-13..-12].present?
35
+ end
36
+
37
+ def prefix_phone
38
+ phone.size == 8 ? phone[-8..-5] : phone[-9..-5]
39
+ end
40
+
41
+ def sufix_phone
42
+ phone[-4..-1]
43
+ end
44
+
45
+ def valid?
46
+ ALLOWED_SIZES.include?(phone.size)
47
+ end
48
+ end
49
+ end
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'parsers/parser_phone'
4
+
3
5
  module Interage
4
6
  module PhoneHelper
5
7
  def format_phone(phone)
6
- return if phone.blank?
7
-
8
- phone.to_s.gsub!(/[^0-9]/, '')
9
-
10
- "(#{phone[0, 2]}) #{phone[3, 5]}-#{phone[8, 4]}".strip
8
+ ParserPhone.call(phone)
11
9
  end
12
10
  end
13
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interage-helper
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
  - Walmir Neto
@@ -77,6 +77,7 @@ files:
77
77
  - interage-helper-0.1.0.gem
78
78
  - interage-helper-0.1.1.gem
79
79
  - interage-helper-0.1.2.gem
80
+ - interage-helper-0.1.3.gem
80
81
  - interage-helper.gemspec
81
82
  - lib/generators/interage/helper/install/USAGE
82
83
  - lib/generators/interage/helper/install/install_generator.rb
@@ -86,9 +87,10 @@ files:
86
87
  - lib/interage/application_icon_helper.rb
87
88
  - lib/interage/bootstrap_helper.rb
88
89
  - lib/interage/cep_helper.rb
90
+ - lib/interage/cnpj_helper.rb
89
91
  - lib/interage/cocoon_helper.rb
90
92
  - lib/interage/controller_active_helper.rb
91
- - lib/interage/cpf_cnpj_helper.rb
93
+ - lib/interage/cpf_helper.rb
92
94
  - lib/interage/date_time_helper.rb
93
95
  - lib/interage/favicon_helper.rb
94
96
  - lib/interage/flash_message_helper.rb
@@ -100,6 +102,10 @@ files:
100
102
  - lib/interage/material_design_icons_helper.rb
101
103
  - lib/interage/number_helper.rb
102
104
  - lib/interage/pagination_helper.rb
105
+ - lib/interage/parsers/parser_cep.rb
106
+ - lib/interage/parsers/parser_cnpj.rb
107
+ - lib/interage/parsers/parser_cpf.rb
108
+ - lib/interage/parsers/parser_phone.rb
103
109
  - lib/interage/phone_helper.rb
104
110
  - lib/interage/text_helper.rb
105
111
  - lib/interage/translation_helper.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Interage
4
- module CPFCNPJHelper
5
- def format_cnpj(cnpj)
6
- return if cnpj.blank?
7
-
8
- cnpj.to_s.gsub!(/[^0-9]/, '')
9
-
10
- formatted_cnpj = ["#{cnpj[0, 2]}.#{cnpj[2, 3]}.#{cnpj[5, 3]}",
11
- "#{cnpj[8, 4]}-#{cnpj[12, 2]}"]
12
- formatted_cnpj.join('/').strip
13
- end
14
-
15
- def format_cpf(cpf)
16
- return if cpf.blank?
17
-
18
- cpf.to_s.gsub!(/[^0-9]/, '')
19
-
20
- "#{cpf[0, 3]}.#{cpf[3, 3]}.#{cpf[6, 3]}-#{cpf[9, 2]}".strip
21
- end
22
- end
23
- end