arel_extensions 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d8dec1f213ad0c9708bec8dba67bf1f1e69a08c
4
- data.tar.gz: 0d14b1fab3067c427d370cf0e7b005f3ff285349
3
+ metadata.gz: 3b36bcf361cb8f97341795d3259a5d1b29a9b046
4
+ data.tar.gz: 67c3eafebe0c53790bf4c0f057d90c4fd773311d
5
5
  SHA512:
6
- metadata.gz: 0af7b4d42096aebda99cf375a2757275dfe04820ebc9d54916018eb335b22e086d23a17e0b9e48559add9bc49830c60001e96a9e68aaf84ad17eb8f750b4800d
7
- data.tar.gz: 4b747e27a9d89aef3fa764625f19210f166bf8bcd81996728e4818fb62a3fb154322159494e90ca67dccc386fa5c13ebeee2b94957146c65f2f3aab7974e2773
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
 
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.1.1".freeze
2
+ VERSION = "1.1.2".freeze
3
3
  end
@@ -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
- nines_before = (1..16).map{'9'}.join('')
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
- number = number.replace('E','e')
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' => '.', 'fr_FR' => ',' }
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 = (1..16).map{'9'}.join('')
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('TO_CHAR',[
295
- col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor),
296
- Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
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('TO_CHAR',[
300
- col.abs.log10.floor,
301
- Arel::Nodes.build_quoted('FM'+nines_before)
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('TO_CHAR',[
306
- Arel::Nodes.build_quoted(col.abs),
307
- Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
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.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: 2018-12-10 00:00:00.000000000 Z
13
+ date: 2019-01-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: arel