eac_rails_utils 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/eac_rails_utils.rb +4 -2
- data/lib/eac_rails_utils/helpers/formatter.rb +36 -0
- data/lib/eac_rails_utils/version.rb +1 -1
- data/test/lib/eac_rails_utils/helpers/formatter_test.rb +22 -0
- metadata +37 -31
- data/lib/eac/formatter_helper.rb +0 -27
- data/test/lib/eac/formatter_helper_test.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eeecb5a7613a760542d6b220abdd21b3c2019896f9b9d41ed0c21aee81aa123
|
4
|
+
data.tar.gz: '0559817915097129faca0f1723d5e0c5c9e2b8b1417f535359446f2bbeffb440'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ae35dba7d708e6e8c5abfa6494b8f954c879c1b12e916e7f42781f277b3132f546e618590eadab2804219aa6b17f825c14a8e76a464936c9bc30c527bea3e7
|
7
|
+
data.tar.gz: 6b35ecb2095434479d2c983d6a4cc972934c023836f6bc7e26933a8334e4ef268e6547c689eb86fc28b981a5d6a724b200a19209d543c42b74371d4a2c60af5b
|
data/lib/eac_rails_utils.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'active_support/dependencies'
|
3
|
+
|
2
4
|
module EacRailsUtils
|
3
5
|
require 'activemodel/associations'
|
4
6
|
require 'nested_form_fields'
|
5
7
|
require 'ofx-parser'
|
6
8
|
require 'virtus'
|
7
9
|
|
10
|
+
require_dependency 'eac_rails_utils/helpers/formatter'
|
8
11
|
require 'eac_rails_utils/patches/action_controller_base'
|
9
12
|
require 'eac_rails_utils/patches/model_attribute_required'
|
10
13
|
require 'eac_rails_utils/patches/ofx_parser'
|
11
14
|
require 'eac_rails_utils/rails/engine'
|
12
15
|
require 'eac_rails_utils/tableless_model'
|
13
16
|
require 'eac/cpf_validator'
|
14
|
-
require 'eac/formatter_helper'
|
15
17
|
require 'eac/common_form_helper/form_builder/association_select_field'
|
16
18
|
require 'eac/common_form_helper/form_builder/common_text_fields'
|
17
19
|
require 'eac/common_form_helper/form_builder/currency_field'
|
@@ -42,8 +44,8 @@ module EacRailsUtils
|
|
42
44
|
require 'eac/source_target_fixtures'
|
43
45
|
require 'eac/test_utils'
|
44
46
|
|
47
|
+
ActionView::Base.send :include, ::EacRailsUtils::Helpers::Formatter
|
45
48
|
ActionView::Base.send :include, Eac::CommonFormHelper
|
46
49
|
ActionView::Base.send :include, Eac::DataTableHelper
|
47
|
-
ActionView::Base.send :include, Eac::FormatterHelper
|
48
50
|
ActionView::Base.send :include, Eac::MenusHelper
|
49
51
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EacRailsUtils
|
3
|
+
module Helpers
|
4
|
+
module Formatter
|
5
|
+
include ActionView::Helpers::NumberHelper
|
6
|
+
|
7
|
+
def value_or_sign(value, sign = '-', &block)
|
8
|
+
return sign if value.blank?
|
9
|
+
return yield(value) if block
|
10
|
+
value
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_real(value)
|
14
|
+
number_to_currency(
|
15
|
+
value,
|
16
|
+
unit: 'R$ ',
|
17
|
+
separator: ',',
|
18
|
+
delimiter: '.',
|
19
|
+
raise: true
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_percentage(float_value)
|
24
|
+
number_to_percentage(float_value * 100, precision: 0)
|
25
|
+
end
|
26
|
+
|
27
|
+
def brl_currency_to_float(currency)
|
28
|
+
currency.to_s.gsub(/[R$ .]/, '').tr(',', '.').to_f
|
29
|
+
end
|
30
|
+
|
31
|
+
def format_cep(cep)
|
32
|
+
"#{cep[0, 5]}-#{cep[5, 3]}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module EacRailsUtils
|
5
|
+
module Helpers
|
6
|
+
class FormatterTest < ActionView::TestCase
|
7
|
+
include ::EacRailsUtils::Helpers::Formatter
|
8
|
+
|
9
|
+
test 'should convert BRL currency to float' do
|
10
|
+
brl_currency = { a: '1', b: '1,2', c: '1,23', d: '123.456.789,01',
|
11
|
+
e: 'R$1,23', f: 'R$ 123.4,56' }
|
12
|
+
float_currency = { a: 1, b: 1.2, c: 1.23, d: 123_456_789.01,
|
13
|
+
e: 1.23, f: 123_4.56 }
|
14
|
+
|
15
|
+
brl_currency.each do |k, v|
|
16
|
+
assert_equal float_currency[k], brl_currency_to_float(v),
|
17
|
+
"#{v} should be #{float_currency[k]}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_rails_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- E.A.C.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel-associations
|
@@ -29,6 +29,9 @@ dependencies:
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
36
|
version: 4.2.1
|
34
37
|
type: :runtime
|
@@ -36,6 +39,9 @@ dependencies:
|
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '4.2'
|
44
|
+
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: 4.2.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
@@ -158,7 +164,6 @@ files:
|
|
158
164
|
- lib/eac/data_table_helper/data_table.rb
|
159
165
|
- lib/eac/data_table_helper/setup.rb
|
160
166
|
- lib/eac/download_fixtures.rb
|
161
|
-
- lib/eac/formatter_helper.rb
|
162
167
|
- lib/eac/htmlbeautifier.rb
|
163
168
|
- lib/eac/inequality_queries.rb
|
164
169
|
- lib/eac/listable.rb
|
@@ -175,6 +180,7 @@ files:
|
|
175
180
|
- lib/eac/source_target_fixtures.rb
|
176
181
|
- lib/eac/test_utils.rb
|
177
182
|
- lib/eac_rails_utils.rb
|
183
|
+
- lib/eac_rails_utils/helpers/formatter.rb
|
178
184
|
- lib/eac_rails_utils/patches/action_controller_base.rb
|
179
185
|
- lib/eac_rails_utils/patches/model_attribute_required.rb
|
180
186
|
- lib/eac_rails_utils/patches/ofx_parser.rb
|
@@ -201,7 +207,6 @@ files:
|
|
201
207
|
- test/lib/eac/common_form_helper_test.rb
|
202
208
|
- test/lib/eac/cpf_validator_test.rb
|
203
209
|
- test/lib/eac/data_table_test_helper.rb
|
204
|
-
- test/lib/eac/formatter_helper_test.rb
|
205
210
|
- test/lib/eac/listable_test.rb
|
206
211
|
- test/lib/eac/model_test.rb
|
207
212
|
- test/lib/eac/parsers/files_test_test.rb
|
@@ -215,6 +220,7 @@ files:
|
|
215
220
|
- test/lib/eac/source_target_fixtures_test_files/a.target.yaml
|
216
221
|
- test/lib/eac/source_target_fixtures_test_files/b.source.html
|
217
222
|
- test/lib/eac/source_target_fixtures_test_files/c.target.yaml
|
223
|
+
- test/lib/eac_rails_utils/helpers/formatter_test.rb
|
218
224
|
- test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
|
219
225
|
- test/lib/eac_rails_utils/tableless_model_test.rb
|
220
226
|
- test/test_helper.rb
|
@@ -242,39 +248,39 @@ signing_key:
|
|
242
248
|
specification_version: 4
|
243
249
|
summary: Código reutilizável para as aplicações Rails da E.A.C..
|
244
250
|
test_files:
|
245
|
-
- test/
|
246
|
-
- test/
|
247
|
-
- test/
|
251
|
+
- test/lib/eac_rails_utils/tableless_model_test.rb
|
252
|
+
- test/lib/eac_rails_utils/helpers/formatter_test.rb
|
253
|
+
- test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
|
254
|
+
- test/lib/eac/source_target_fixtures_test.rb
|
255
|
+
- test/lib/eac/listable_test.rb
|
256
|
+
- test/lib/eac/data_table_test_helper.rb
|
257
|
+
- test/lib/eac/cpf_validator_test.rb
|
258
|
+
- test/lib/eac/model_test.rb
|
259
|
+
- test/lib/eac/common_form_helper_test.rb
|
260
|
+
- test/lib/eac/source_target_fixtures_test_files/a.target.yaml
|
261
|
+
- test/lib/eac/source_target_fixtures_test_files/b.source.html
|
262
|
+
- test/lib/eac/source_target_fixtures_test_files/c.target.yaml
|
263
|
+
- test/lib/eac/source_target_fixtures_test_files/a.source.html
|
264
|
+
- test/lib/eac/simple_cache_test.rb
|
265
|
+
- test/lib/eac/parsers/files_test_test.rb
|
266
|
+
- test/lib/eac/parsers/ok_test_files/a.target.yaml
|
267
|
+
- test/lib/eac/parsers/ok_test_files/b.source.yaml
|
268
|
+
- test/lib/eac/parsers/ok_test_files/b.target.yaml
|
269
|
+
- test/lib/eac/parsers/ok_test_files/a.source.yaml
|
270
|
+
- test/dummy/config/routes.rb
|
248
271
|
- test/dummy/config/database.yml
|
249
272
|
- test/dummy/config/secrets.yml
|
250
273
|
- test/dummy/config/locales/pt-BR.yml
|
274
|
+
- test/dummy/config/environment.rb
|
275
|
+
- test/dummy/config/boot.rb
|
251
276
|
- test/dummy/config/application.rb
|
252
277
|
- test/dummy/config/environments/test.rb
|
253
|
-
- test/dummy/
|
254
|
-
- test/dummy/config
|
278
|
+
- test/dummy/Rakefile
|
279
|
+
- test/dummy/config.ru
|
280
|
+
- test/dummy/app/models/user.rb
|
281
|
+
- test/dummy/app/models/job.rb
|
255
282
|
- test/dummy/db/schema.rb
|
283
|
+
- test/dummy/db/migrate/20160415125333_create_users.rb
|
256
284
|
- test/dummy/db/migrate/20160415143123_create_jobs.rb
|
257
285
|
- test/dummy/db/migrate/20160415143229_add_job_to_users.rb
|
258
|
-
- test/dummy/db/migrate/20160415125333_create_users.rb
|
259
|
-
- test/dummy/app/models/job.rb
|
260
|
-
- test/dummy/app/models/user.rb
|
261
286
|
- test/test_helper.rb
|
262
|
-
- test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
|
263
|
-
- test/lib/eac_rails_utils/tableless_model_test.rb
|
264
|
-
- test/lib/eac/common_form_helper_test.rb
|
265
|
-
- test/lib/eac/source_target_fixtures_test.rb
|
266
|
-
- test/lib/eac/parsers/files_test_test.rb
|
267
|
-
- test/lib/eac/parsers/ok_test_files/a.source.yaml
|
268
|
-
- test/lib/eac/parsers/ok_test_files/a.target.yaml
|
269
|
-
- test/lib/eac/parsers/ok_test_files/b.source.yaml
|
270
|
-
- test/lib/eac/parsers/ok_test_files/b.target.yaml
|
271
|
-
- test/lib/eac/cpf_validator_test.rb
|
272
|
-
- test/lib/eac/data_table_test_helper.rb
|
273
|
-
- test/lib/eac/simple_cache_test.rb
|
274
|
-
- test/lib/eac/formatter_helper_test.rb
|
275
|
-
- test/lib/eac/source_target_fixtures_test_files/c.target.yaml
|
276
|
-
- test/lib/eac/source_target_fixtures_test_files/b.source.html
|
277
|
-
- test/lib/eac/source_target_fixtures_test_files/a.target.yaml
|
278
|
-
- test/lib/eac/source_target_fixtures_test_files/a.source.html
|
279
|
-
- test/lib/eac/listable_test.rb
|
280
|
-
- test/lib/eac/model_test.rb
|
data/lib/eac/formatter_helper.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Eac
|
2
|
-
module FormatterHelper
|
3
|
-
include ActionView::Helpers::NumberHelper
|
4
|
-
|
5
|
-
def format_real(value)
|
6
|
-
number_to_currency(
|
7
|
-
value,
|
8
|
-
unit: 'R$ ',
|
9
|
-
separator: ',',
|
10
|
-
delimiter: '.',
|
11
|
-
raise: true
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def format_percentage(float_value)
|
16
|
-
number_to_percentage(float_value * 100, precision: 0)
|
17
|
-
end
|
18
|
-
|
19
|
-
def brl_currency_to_float(currency)
|
20
|
-
currency.to_s.gsub(/[R$ .]/, '').tr(',', '.').to_f
|
21
|
-
end
|
22
|
-
|
23
|
-
def format_cep(cep)
|
24
|
-
"#{cep[0, 5]}-#{cep[5, 3]}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Eac
|
4
|
-
class FormatterHelperTest < ActionView::TestCase
|
5
|
-
include Eac::FormatterHelper
|
6
|
-
|
7
|
-
test 'should convert BRL currency to float' do
|
8
|
-
brl_currency = { a: '1', b: '1,2', c: '1,23', d: '123.456.789,01',
|
9
|
-
e: 'R$1,23', f: 'R$ 123.4,56' }
|
10
|
-
float_currency = { a: 1, b: 1.2, c: 1.23, d: 123_456_789.01,
|
11
|
-
e: 1.23, f: 123_4.56 }
|
12
|
-
|
13
|
-
brl_currency.each do |k, v|
|
14
|
-
assert_equal float_currency[k], brl_currency_to_float(v),
|
15
|
-
"#{v} should be #{float_currency[k]}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|