arel_extensions 1.1.1 → 1.1.2
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b36bcf361cb8f97341795d3259a5d1b29a9b046
|
4
|
+
data.tar.gz: 67c3eafebe0c53790bf4c0f057d90c4fd773311d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 844f8c6fecf320902f0ea8d07a52182423ce660307019d8b50a93757332edbc9251549b26f2f091206f79988e923eb437c45cdb5900aa6957325073e52da31a4
|
7
|
+
data.tar.gz: 62b98ce10a839b8aab63a613be066b50356de269f292a1b9d44e4d74b33e2295878b5385e4eba24e090367f4682cce7611a491824050072963ed8daf26e8ad2a
|
@@ -6,6 +6,9 @@ module ArelExtensions
|
|
6
6
|
include Arel::OrderPredications
|
7
7
|
include ArelExtensions::Comparators
|
8
8
|
include ArelExtensions::Predications
|
9
|
+
include ArelExtensions::MathFunctions
|
10
|
+
include ArelExtensions::StringFunctions
|
11
|
+
include ArelExtensions::NullFunctions
|
9
12
|
|
10
13
|
attr_accessor :case, :conditions, :default
|
11
14
|
|
@@ -9,7 +9,7 @@ module ArelExtensions
|
|
9
9
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
10
10
|
'%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
|
11
11
|
}
|
12
|
-
Arel::Visitors::Oracle::NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ', ' }
|
12
|
+
Arel::Visitors::Oracle::NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
|
13
13
|
|
14
14
|
def visit_ArelExtensions_Nodes_Log10 o, collector
|
15
15
|
collector << "LOG("
|
@@ -521,9 +521,14 @@ module ArelExtensions
|
|
521
521
|
col = o.left
|
522
522
|
comma = Arel::Visitors::Oracle::NUMBER_COMMA_MAPPING[o.locale] || '.,'
|
523
523
|
comma_in_format = o.precision == 0 ? '' : 'D'
|
524
|
-
options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+"'")
|
525
524
|
nines_after = (1..o.precision).map{'9'}.join('')
|
526
|
-
|
525
|
+
if comma.length == 1
|
526
|
+
options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+" '")
|
527
|
+
nines_before = ("999"*4+"990")
|
528
|
+
else
|
529
|
+
options = Arel::Nodes.build_quoted("NLS_NUMERIC_CHARACTERS = '"+comma+"'")
|
530
|
+
nines_before = ("999G"*4+"990")
|
531
|
+
end
|
527
532
|
sign = ArelExtensions::Nodes::Case.new.when(col<0).
|
528
533
|
then('-').
|
529
534
|
else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
|
@@ -538,7 +543,7 @@ module ArelExtensions
|
|
538
543
|
options
|
539
544
|
])
|
540
545
|
if o.type == 'e'
|
541
|
-
|
546
|
+
number = number.replace('E','e')
|
542
547
|
end
|
543
548
|
else
|
544
549
|
number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
@@ -8,7 +8,7 @@ module ArelExtensions
|
|
8
8
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
9
9
|
'%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
|
10
10
|
}
|
11
|
-
Arel::Visitors::PostgreSQL::NUMBER_COMMA_MAPPING = { 'en_US' => '
|
11
|
+
Arel::Visitors::PostgreSQL::NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
|
12
12
|
|
13
13
|
def visit_ArelExtensions_Nodes_Rand o, collector
|
14
14
|
collector << "RANDOM("
|
@@ -281,9 +281,11 @@ module ArelExtensions
|
|
281
281
|
|
282
282
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
283
283
|
col = o.left
|
284
|
-
comma = o.precision == 0 ? '' : (Arel::Visitors::PostgreSQL::NUMBER_COMMA_MAPPING[o.locale] || '.')
|
284
|
+
comma = o.precision == 0 ? '' : (Arel::Visitors::PostgreSQL::NUMBER_COMMA_MAPPING[o.locale][0] || '.')
|
285
|
+
thousand_separator = Arel::Visitors::PostgreSQL::NUMBER_COMMA_MAPPING[o.locale][1] || (Arel::Visitors::PostgreSQL::NUMBER_COMMA_MAPPING[o.locale] ? '' : 'G')
|
285
286
|
nines_after = (1..o.precision).map{'9'}.join('')
|
286
|
-
nines_before = (
|
287
|
+
nines_before = ("999#{thousand_separator}"*4+"990")
|
288
|
+
|
287
289
|
sign = ArelExtensions::Nodes::Case.new.when(col<0).
|
288
290
|
then('-').
|
289
291
|
else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
|
@@ -291,21 +293,24 @@ module ArelExtensions
|
|
291
293
|
|
292
294
|
if o.scientific_notation
|
293
295
|
number = ArelExtensions::Nodes::Concat.new([
|
294
|
-
Arel::Nodes::NamedFunction.new('
|
295
|
-
|
296
|
-
|
297
|
-
|
296
|
+
Arel::Nodes::NamedFunction.new('TRIM',[
|
297
|
+
Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
298
|
+
col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor),
|
299
|
+
Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
|
300
|
+
])]),
|
298
301
|
o.type,
|
299
|
-
Arel::Nodes::NamedFunction.new('
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
302
|
+
Arel::Nodes::NamedFunction.new('TRIM',[
|
303
|
+
Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
304
|
+
col.abs.log10.floor,
|
305
|
+
Arel::Nodes.build_quoted('FM'+nines_before)
|
306
|
+
])])
|
307
|
+
])
|
304
308
|
else
|
305
|
-
number = Arel::Nodes::NamedFunction.new('
|
306
|
-
Arel::Nodes.
|
307
|
-
|
308
|
-
|
309
|
+
number = Arel::Nodes::NamedFunction.new('TRIM',[
|
310
|
+
Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
311
|
+
Arel::Nodes.build_quoted(col.abs),
|
312
|
+
Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
|
313
|
+
])])
|
309
314
|
end
|
310
315
|
|
311
316
|
repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
|
@@ -520,9 +520,13 @@ module ArelExtensions
|
|
520
520
|
assert_equal "$ 65,6 €" , t(@arthur, @score.format_number("$ % 7.1f €","fr_FR"))
|
521
521
|
assert_equal "$ +65,62 €" , t(@arthur, @score.format_number("$ % +7.2f €","fr_FR"))
|
522
522
|
assert_equal "$ +065,62 €" , t(@arthur, @score.format_number("$ %0+7.2f €","fr_FR"))
|
523
|
-
assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
|
524
|
-
assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
|
523
|
+
assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
|
524
|
+
assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
|
525
525
|
assert_includes ["$ 6,562E1 €","$ 6,562E+01 €"], t(@arthur, @score.format_number("$ %.3E €","fr_FR"))
|
526
|
+
assert_equal "123 456 765,6" , t(@arthur, (@score+123456700).format_number("%.1f","sv_SE"))
|
527
|
+
assert_equal "123456765,6" , t(@arthur, (@score+123456700).format_number("%.1f","fr_FR"))
|
528
|
+
assert_equal "123,456,765.6" , t(@arthur, (@score+123456700).format_number("%.1f","en_US"))
|
529
|
+
assert_equal " 123,456,765.6" , t(@arthur, (@score+123456700).format_number("%16.1f","en_US"))
|
526
530
|
end
|
527
531
|
|
528
532
|
def test_accent_insensitive
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yann Azoury
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: arel
|