lucarecord 0.2.20 → 0.2.21

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
  SHA256:
3
- metadata.gz: e2644c50f67e64dfe2502400e04eddb6278a314d00f82eb5a51a6489797f0b48
4
- data.tar.gz: c6d286442884c6675f18340ad2eb3322cd76515992530cbf4fc8536b66a6bbad
3
+ metadata.gz: 94f10c954f77059dc814f1aac38335ca0e1597d0db8e7e754a93f6a67714cce1
4
+ data.tar.gz: fd0e684124f7683e49192b231fd8f245e09c1fdd281f88fac7dcc309f92713bf
5
5
  SHA512:
6
- metadata.gz: 0122e43160066ce33dad8478fc99cd4bc639abf232788852ebce74328f664f413756ea91c73a6f6372f4dce9648a9c6776dd7f7ee1f0971930b71f0816a2841b
7
- data.tar.gz: '09c51366863747bfea0cdf829d0829be6d084b79cbc729c3cb51ecea7f07196ca2c7ff0eea8b52d834d0af476de9cb953ef50d9e1b7e620de0c6f5d51c64f158'
6
+ metadata.gz: bfd7fdcc8f63dc889fcd51ae8e6e9d8a842a2b87ac5e7c7235e6c1ca9aa5f3886d86f8af71de0bf5e379a428b4c9fa15a2f300118427849da46124fcf4ee7532
7
+ data.tar.gz: 7e39c7ada92fbc48aad6492362d9f22f8cfa2c3fa109183410d5de9f64641b8d566c206d165026a92f48dd2aa6b2aa310f69a1ff1d7fefc43f48226b5d2065e5
@@ -1,3 +1,7 @@
1
+ ## LucaRecord 0.2.21
2
+
3
+ * Enhance `LucaSupport::Code.delimit_num()`. Handle with BigDecimal, decimal length & delmiter customization.
4
+
1
5
  ## LucaRecord 0.2.20
2
6
 
3
7
  * UUID completion framework on prefix match
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.2.20'
4
+ VERSION = '0.2.21'
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module LucaSupport
4
4
  autoload :Code, 'luca_support/code'
5
+ autoload :CONFIG, 'luca_support/config'
5
6
  autoload :Config, 'luca_support/config'
6
7
  autoload :Mail, 'luca_support/mail'
7
8
  autoload :View, 'luca_support/view'
@@ -48,8 +48,27 @@ module LucaSupport
48
48
  '0123456789ABCDEFGHIJKLMNOPQRSTUV'.index(char)
49
49
  end
50
50
 
51
- def delimit_num(num)
52
- num.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1,').reverse!
51
+ # Format number in 3-digit-group.
52
+ # Long decimal is just ommitted with floor().
53
+ #
54
+ def delimit_num(num, decimal: nil, delimiter: nil)
55
+ return nil if num.nil?
56
+
57
+ decimal ||= LucaSupport::Config::DECIMAL_NUM
58
+ str = case num
59
+ when BigDecimal
60
+ if decimal == 0
61
+ num.floor.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
62
+ else
63
+ fragments = num.floor(decimal).to_s('F').split('.')
64
+ fragments[0].reverse!.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
65
+ fragments[1].gsub!(/(\d{3})(?=\d)/, '\1 ')
66
+ fragments.join('.')
67
+ end
68
+ else
69
+ num.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
70
+ end
71
+ delimiter.nil? ? str : str.gsub!(/\s/, delimiter)
53
72
  end
54
73
 
55
74
  # encode directory name from year and month.
@@ -3,10 +3,16 @@
3
3
  require 'pathname'
4
4
  require 'yaml'
5
5
 
6
- #
7
6
  # startup config
8
7
  #
9
8
  module LucaSupport
9
+ PJDIR = ENV['LUCA_TEST_DIR'] || Dir.pwd.freeze
10
+ CONFIG = begin
11
+ YAML.load_file(Pathname(PJDIR) / 'config.yml', **{})
12
+ rescue Errno::ENOENT
13
+ {}
14
+ end
15
+
10
16
  module Config
11
17
  # Project top directory.
12
18
  Pjdir = ENV['LUCA_TEST_DIR'] || Dir.pwd.freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucarecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.20
4
+ version: 0.2.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2020-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail