lucarecord 0.2.18 → 0.2.19

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
  SHA256:
3
- metadata.gz: 63ac71426bdf4eb871884b8b28c5aa363db9d51ef3ca0d84ab92a3fcf127ecde
4
- data.tar.gz: 2bc0d6ecde974a2f9ca9c901af5ac714c909f40dd84986746948065a4efb4ed7
3
+ metadata.gz: e5d79527ced912cddc0f5d33e7d557dd23fb2e2ae0ed0437f7c90eb44095469e
4
+ data.tar.gz: ce8fc1c4ec1264913024981a6769a36d6439d6d5b89a820bcfa7fcb6991151bb
5
5
  SHA512:
6
- metadata.gz: 1f9cf84bfb09080f6f3e8cf15c8fb3cea0d6eca9d69acc10c23cd9b6a681daae9ab641181a928f438c870a438a0c4525c61bfad6a1832a2d148b7a3d37b3d6d3
7
- data.tar.gz: be35bd6b0a993b5fde415ba5e1a7b59228106c443594b164fa5df26f1eb284ae0556277b99b25f7697283ac194f6c25ffa7d7d8d3e1bfe2e22b128130f3f9cec
6
+ metadata.gz: f4f62de1a08971733954c469d2572f6aab8018379de928ab2413aca14d9123b08da67e5f85dcd8bf632c646732cf5c534f259bd83fb5eeff0d851e4d444b7e1c
7
+ data.tar.gz: 2ef832f91abef366760fbff0157c97c9e43a814b1df6f1c5244e0e0f7ad32db8459f2abee51fd1fd40812283b87b6b2a1140d6668b98ab98d86088d17d3bb0e4
@@ -1,3 +1,8 @@
1
+ ## LucaRecord 0.2.19
2
+
3
+ * `LucaSupport::Code.decode_id()`
4
+ * `LucaSupport::Code.encode_term()` for multiple months search. Old `scan_term()` removed.
5
+
1
6
  ## LucaRecord 0.2.18
2
7
 
3
8
  * `find()`, `create()`, `save()` now supports both of uuid / historical records. If specified `date:` keyword option to `create()`, then generate historical record. `find()`, `save()` identifies with 'id' attribute.
@@ -20,7 +20,7 @@ module LucaRecord
20
20
  end
21
21
 
22
22
  def search(word, default_word = nil)
23
- res = max_score_code(word)
23
+ res = max_score_code(word.gsub(/[[:space:]]/, ''))
24
24
  if res[1] > 0.4
25
25
  res[0]
26
26
  else
@@ -65,7 +65,7 @@ module LucaRecord
65
65
  config[:type] ||= 'invalid'
66
66
  config[:debit_value] = @config['debit_value'].to_i if @config.dig('debit_value')
67
67
  config[:credit_value] = @config['credit_value'].to_i if @config.dig('credit_value')
68
- config[:note] = @config['note'].to_i if @config.dig('note')
68
+ config[:note] = @config['note'] if @config.dig('note')
69
69
  config[:encoding] = @config['encoding'] if @config.dig('encoding')
70
70
 
71
71
  config[:year] = @config['year'] if @config.dig('year')
@@ -54,8 +54,22 @@ module LucaRecord # :nodoc:
54
54
  def asof(year, month = nil, day = nil, basedir = @dirname)
55
55
  return enum_for(:search, year, month, day, nil, basedir) unless block_given?
56
56
 
57
- search(year, month, day, nil, basedir) do |data, path|
58
- yield data, path
57
+ search(year, month, day, nil, basedir) { |data, path| yield data, path }
58
+ end
59
+
60
+ # scan ranging data on multiple months
61
+ #
62
+ def term(start_year, start_month, end_year, end_month, code = nil, basedir = @dirname)
63
+ return enum_for(:term, start_year, start_month, end_year, end_month, code, basedir) unless block_given?
64
+
65
+ LucaSupport::Code.encode_term(start_year, start_month, end_year, end_month).each do |subdir|
66
+ open_records(basedir, subdir, nil, code) do |f, path|
67
+ if @record_type == 'raw'
68
+ yield f, path
69
+ else
70
+ yield load_data(f, path)
71
+ end
72
+ end
59
73
  end
60
74
  end
61
75
 
@@ -148,6 +162,21 @@ module LucaRecord # :nodoc:
148
162
  id
149
163
  end
150
164
 
165
+ # change filename with new code set
166
+ #
167
+ def change_codes(id, new_codes, basedir = @dirname)
168
+ raise 'invalid id' if id.split('/').length != 2
169
+
170
+ newfile = new_codes.empty? ? id : id + '-' + new_codes.join('-')
171
+ Dir.chdir(abs_path(basedir)) do
172
+ origin = Dir.glob("#{id}*")
173
+ raise 'duplicated files' if origin.length != 1
174
+
175
+ File.rename(origin.first, newfile)
176
+ end
177
+ newfile
178
+ end
179
+
151
180
  # ----------------------------------------------------------------
152
181
  # :section: Path Utilities
153
182
  # ----------------------------------------------------------------
@@ -270,6 +299,17 @@ module LucaRecord # :nodoc:
270
299
  end
271
300
  end
272
301
 
302
+ # parse data dir and respond existing months
303
+ #
304
+ def scan_terms(query = nil, base_dir = @dirname)
305
+ pattern = query.nil? ? "*" : "#{query}*"
306
+ Dir.chdir(abs_path(base_dir)) do
307
+ Dir.glob(pattern).select { |dir|
308
+ FileTest.directory?(dir) && /^[0-9]/.match(dir)
309
+ }.sort.map { |str| decode_term(str) }
310
+ end
311
+ end
312
+
273
313
  # Decode basic format.
274
314
  # If specific decode is needed, override this method in each class.
275
315
  #
@@ -281,8 +321,7 @@ module LucaRecord # :nodoc:
281
321
  when 'json'
282
322
  # TODO: implement JSON parse
283
323
  else
284
- YAML.load(io.read).tap { |obj| validate_keys(obj) }
285
- .inject({}) { |h, (k, v)| h[k] = LucaSupport::Code.decimalize(v); h }
324
+ LucaSupport::Code.decimalize(YAML.load(io.read)).tap { |obj| validate_keys(obj) }
286
325
  end
287
326
  end
288
327
 
@@ -348,17 +387,6 @@ module LucaRecord # :nodoc:
348
387
  end
349
388
  end
350
389
 
351
- # parse data dir and respond existing months
352
- #
353
- def scan_terms(base_dir, query = nil)
354
- pattern = query.nil? ? "*" : "#{query}*"
355
- Dir.chdir(base_dir) do
356
- Dir.glob(pattern).select { |dir|
357
- FileTest.directory?(dir) && /^[0-9]/.match(dir)
358
- }.sort.map { |str| decode_term(str) }
359
- end
360
- end
361
-
362
390
  def load_config(path = nil)
363
391
  path = path.to_s
364
392
  if File.exist?(path)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.2.18'
4
+ VERSION = '0.2.19'
5
5
  end
@@ -10,6 +10,13 @@ module LucaSupport
10
10
  module Code
11
11
  module_function
12
12
 
13
+ # Parse historical id into Array of date & transaction id.
14
+ #
15
+ def decode_id(id_str)
16
+ m = %r(^(?<year>[0-9]+)(?<month>[A-L])/?(?<day>[0-9A-V])(?<txid>[0-9A-Z]{,3})).match(id_str)
17
+ ["#{m[:year]}-#{decode_month(m[:month])}-#{decode_date(m[:day])}", decode_txid(m[:txid])]
18
+ end
19
+
13
20
  def encode_txid(num)
14
21
  txmap = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
15
22
  l = txmap.length
@@ -69,6 +76,16 @@ module LucaSupport
69
76
  '0ABCDEFGHIJKL'.index(char)
70
77
  end
71
78
 
79
+ # Generate globbing phrase like ["2020[C-H]"] for range search.
80
+ #
81
+ def encode_term(start_year, start_month, end_year, end_month)
82
+ (start_year..end_year).to_a.map do |y|
83
+ g1 = y == start_year ? encode_month(start_month) : encode_month(1)
84
+ g2 = y == end_year ? encode_month(end_month) : encode_month(12)
85
+ "#{y}[#{g1}-#{g2}]"
86
+ end
87
+ end
88
+
72
89
  def decode_term(char)
73
90
  m = /^([0-9]{4})([A-La-l])/.match(char)
74
91
  [m[1].to_i, decode_month(m[2])]
@@ -11,7 +11,7 @@ module LucaSupport
11
11
  # Project top directory.
12
12
  Pjdir = ENV['LUCA_TEST_DIR'] || Dir.pwd.freeze
13
13
  if File.exist?(Pathname(Pjdir) / 'config.yml')
14
- DECIMAL_NUM = YAML.load_file(Pathname(Pjdir) / 'config.yml', **{})['decimal_number']
14
+ # DECIMAL_NUM = YAML.load_file(Pathname(Pjdir) / 'config.yml', **{})['decimal_number']
15
15
  COUNTRY = YAML.load_file(Pathname(Pjdir) / 'config.yml', **{})['country']
16
16
  DECIMAL_NUM ||= 0 if COUNTRY == 'jp'
17
17
  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.18
4
+ version: 0.2.19
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-08 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail