lucarecord 0.2.23 → 0.2.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/luca_record/base.rb +2 -0
- data/lib/luca_record/dict.rb +1 -1
- data/lib/luca_record/io.rb +2 -2
- data/lib/luca_record/version.rb +1 -1
- data/lib/luca_support/code.rb +33 -16
- data/lib/luca_support/config.rb +9 -13
- data/lib/luca_support/view.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88e839f7ee18513f3798a568e65bd067eb16b87209f895f1b13a0deb43433837
|
4
|
+
data.tar.gz: 9292a2d9a8e53cab0b5d4aabcea77f5a9a45f8fb504e048ac081a22e86b2ae28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d39c80ffea32406bd009cbd1c3393a8c02c52128ac6365f395ff68af2f1b8964aa1bdd2b7f951dab00aad00a3659bff2883dd839e3179bd013b8e1026185d5
|
7
|
+
data.tar.gz: 8577ad3aee104dc8341b20ec04aae3f18a0145ca826165696f726cce4a2f25661c1205fb79ce2e43d5d361f7c89a449607f8854349c7ea0c6a6a987da1c3aaee
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## LucaRecord 0.2.24
|
2
|
+
|
3
|
+
* Digit delimiter for `delimit_num` can be customized through `thousands_separator` and `decimal_separator` in config.yml.
|
4
|
+
* Const `CONFIG` and `PJDIR` is defined at `LucaRecord::Base`.
|
5
|
+
* add `LucaSupport::Code.keys_stringify()`
|
6
|
+
|
1
7
|
## LucaRecord 0.2.23
|
2
8
|
|
3
9
|
* Enhance Dictionary, supporting extensible options.
|
data/lib/luca_record/base.rb
CHANGED
data/lib/luca_record/dict.rb
CHANGED
data/lib/luca_record/io.rb
CHANGED
@@ -243,7 +243,7 @@ module LucaRecord # :nodoc:
|
|
243
243
|
end
|
244
244
|
|
245
245
|
# test if having required dirs/files under exec path
|
246
|
-
def valid_project?(path = LucaSupport::
|
246
|
+
def valid_project?(path = LucaSupport::PJDIR)
|
247
247
|
project_dir = Pathname(path)
|
248
248
|
FileTest.file?((project_dir + 'config.yml').to_s) and FileTest.directory?( (project_dir + 'data').to_s)
|
249
249
|
end
|
@@ -362,7 +362,7 @@ module LucaRecord # :nodoc:
|
|
362
362
|
|
363
363
|
# TODO: replace with data_dir method
|
364
364
|
def abs_path(base_dir)
|
365
|
-
Pathname(LucaSupport::
|
365
|
+
Pathname(LucaSupport::PJDIR) / 'data' / base_dir
|
366
366
|
end
|
367
367
|
|
368
368
|
# true when file doesn't have record on code
|
data/lib/luca_record/version.rb
CHANGED
data/lib/luca_support/code.rb
CHANGED
@@ -54,21 +54,24 @@ module LucaSupport
|
|
54
54
|
def delimit_num(num, decimal: nil, delimiter: nil)
|
55
55
|
return nil if num.nil?
|
56
56
|
|
57
|
-
decimal ||= LucaSupport::
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
decimal ||= LucaSupport::CONFIG['decimal_num']
|
58
|
+
delimiter ||= LucaSupport::CONFIG['thousands_separator']
|
59
|
+
case num
|
60
|
+
when BigDecimal
|
61
|
+
if decimal == 0
|
62
|
+
num.floor.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
|
63
|
+
.gsub!(/\s/, delimiter)
|
64
|
+
else
|
65
|
+
fragments = num.floor(decimal).to_s('F').split('.')
|
66
|
+
fragments[0].reverse!.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
|
67
|
+
.gsub!(/\s/, delimiter)
|
68
|
+
fragments[1].gsub!(/(\d{3})(?=\d)/, '\1 ')
|
69
|
+
fragments.join(LucaSupport::CONFIG['decimal_separator'])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
num.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
|
73
|
+
.gsub!(/\s/, delimiter)
|
74
|
+
end
|
72
75
|
end
|
73
76
|
|
74
77
|
# encode directory name from year and month.
|
@@ -114,6 +117,20 @@ module LucaSupport
|
|
114
117
|
Digest::SHA1.hexdigest(SecureRandom.uuid)
|
115
118
|
end
|
116
119
|
|
120
|
+
# Convert Hash keys to string recursively.
|
121
|
+
# Required for YAML compatibility.
|
122
|
+
#
|
123
|
+
def keys_stringify(dat)
|
124
|
+
case dat
|
125
|
+
when Array
|
126
|
+
dat.map { |d| keys_stringify(d) }
|
127
|
+
when Hash
|
128
|
+
dat.map { |k, v| [k.to_s, keys_stringify(v)] }.to_h
|
129
|
+
else
|
130
|
+
dat
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
117
134
|
def match_score(a, b, n = 2)
|
118
135
|
v_a = to_ngram(a, n)
|
119
136
|
v_b = to_ngram(b, n)
|
@@ -142,7 +159,7 @@ module LucaSupport
|
|
142
159
|
end
|
143
160
|
end
|
144
161
|
|
145
|
-
def readable(obj, len = LucaSupport::
|
162
|
+
def readable(obj, len = LucaSupport::CONFIG['decimal_num'])
|
146
163
|
case obj
|
147
164
|
when Array
|
148
165
|
obj.map { |i| readable(i) }
|
data/lib/luca_support/config.rb
CHANGED
@@ -8,19 +8,15 @@ require 'yaml'
|
|
8
8
|
module LucaSupport
|
9
9
|
PJDIR = ENV['LUCA_TEST_DIR'] || Dir.pwd.freeze
|
10
10
|
CONFIG = begin
|
11
|
-
|
11
|
+
{
|
12
|
+
'decimal_separator' => '.',
|
13
|
+
'thousands_separator' => ','
|
14
|
+
}.merge(YAML.load_file(Pathname(PJDIR) / 'config.yml'))
|
12
15
|
rescue Errno::ENOENT
|
13
|
-
{
|
16
|
+
{
|
17
|
+
'decimal_separator' => '.',
|
18
|
+
'thousands_separator' => ','
|
19
|
+
}
|
14
20
|
end
|
15
|
-
|
16
|
-
module Config
|
17
|
-
# Project top directory.
|
18
|
-
Pjdir = ENV['LUCA_TEST_DIR'] || Dir.pwd.freeze
|
19
|
-
if File.exist?(Pathname(Pjdir) / 'config.yml')
|
20
|
-
# DECIMAL_NUM = YAML.load_file(Pathname(Pjdir) / 'config.yml', **{})['decimal_number']
|
21
|
-
COUNTRY = YAML.load_file(Pathname(Pjdir) / 'config.yml', **{})['country']
|
22
|
-
DECIMAL_NUM ||= 0 if COUNTRY == 'jp'
|
23
|
-
end
|
24
|
-
DECIMAL_NUM ||= 2
|
25
|
-
end
|
21
|
+
CONFIG['decimal_num'] ||= CONFIG['country'] == 'jp' ? 0 : 2
|
26
22
|
end
|
data/lib/luca_support/view.rb
CHANGED
@@ -36,7 +36,7 @@ module LucaSupport
|
|
36
36
|
|
37
37
|
def search_template(file, dir = 'templates')
|
38
38
|
# TODO: load config
|
39
|
-
[
|
39
|
+
[LucaSupport::PJDIR, lib_path].each do |base|
|
40
40
|
path = (Pathname(base) / dir / file)
|
41
41
|
return path.to_path if path.file?
|
42
42
|
end
|
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.
|
4
|
+
version: 0.2.24
|
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-
|
11
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|