lucabook 0.2.11 → 0.2.12

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: 8e668b84de17897d833b8cdc2af8a8cc6086485c1369116136d4d1eee68c3b32
4
- data.tar.gz: 0c088d2d8e39c9e99332888d0dbeed1fe076a1dc789d901b18912acbeedea4ef
3
+ metadata.gz: b58568499ebfa245c9f86863537eb2a9b26e563ac20a09583a3b12e29bc713a2
4
+ data.tar.gz: 77a382f306e0c269182caca7d48bb6fd8d4f6513664d8cef36a28356cacd8998
5
5
  SHA512:
6
- metadata.gz: cd69cd58f5e5c76e958a18d49b5458b85ed72293afeffca8da0c0df5a454cc34703d294c9de163a4d0a44318bd203467f41ab94e0820c0728b13fac6dcbd1586
7
- data.tar.gz: d962339bee1cf14732d0e90422915d571a951d9cfd50d5d17998f9d6dc83036ebb9d4e69c1ca6fcd6963f49474ef551d4b408d61dbea8cd9afc12496f4e755a9
6
+ metadata.gz: 1526e2b525c357dc06f87253095a8e8434bacc03994432f90dec6571f4bde9fe24b9d1a81ab3b9747a3d45be767022bb9bf64f1a0b88b298e6997bbb95ca4fd2
7
+ data.tar.gz: 111d7eff70797d30bc2df769cbd3d1c8c8b83d92ef5bba8ffa74b60bc06fa9f0754fd54d507f556f7c9831c87a418113ecc797755436f84926e8df88cf117622
@@ -48,13 +48,13 @@ module LucaBook
48
48
  d['debit'].each { |h| h['code'] = @dict.search(h['label'], DEBIT_DEFAULT) }
49
49
  d['credit'].each { |h| h['code'] = @dict.search(h['label'], CREDIT_DEFAULT) }
50
50
 
51
- LucaBook.new.create!(d)
51
+ LucaBook.new.create(d)
52
52
  end
53
53
 
54
54
  def import_csv
55
55
  @dict.load_csv(@target_file) do |row|
56
56
  if @config[:type] == 'single'
57
- LucaBook::Journal.create!(parse_single(row))
57
+ LucaBook::Journal.create(parse_single(row))
58
58
  elsif @config[:type] == 'double'
59
59
  p parse_double(row)
60
60
  else
@@ -68,7 +68,7 @@ module LucaBook
68
68
  #
69
69
  def parse_single(row)
70
70
  value = row.dig(@config[:credit_value])&.empty? ? row[@config[:debit_value]] : row[@config[:credit_value]]
71
- {}.tap do |d|
71
+ {}.tap do |d|
72
72
  d['date'] = parse_date(row)
73
73
  if row.dig(@config[:credit_value])&.empty?
74
74
  d['debit'] = [
@@ -12,28 +12,36 @@ module LucaBook
12
12
 
13
13
  # create journal from hash
14
14
  #
15
- def self.create!(d)
15
+ def self.create(d)
16
16
  date = Date.parse(d['date'])
17
17
 
18
- debit_amount = serialize_on_key(d['debit'], 'value')
19
- credit_amount = serialize_on_key(d['credit'], 'value')
18
+ debit_amount = LucaSupport::Code.decimalize(serialize_on_key(d['debit'], 'value'))
19
+ credit_amount = LucaSupport::Code.decimalize(serialize_on_key(d['credit'], 'value'))
20
20
  raise 'BalanceUnmatch' if debit_amount.inject(:+) != credit_amount.inject(:+)
21
21
 
22
22
  debit_code = serialize_on_key(d['debit'], 'code')
23
23
  credit_code = serialize_on_key(d['credit'], 'code')
24
24
 
25
- # TODO: limit code length for filename
26
- codes = (debit_code + credit_code).uniq
25
+ # TODO: need to sync filename & content. Limit code length for filename
26
+ # codes = (debit_code + credit_code).uniq
27
+ codes = nil
27
28
  create_record!(date, codes) do |f|
28
29
  f << debit_code
29
- f << debit_amount
30
+ f << LucaSupport::Code.readable(debit_amount)
30
31
  f << credit_code
31
- f << credit_amount
32
+ f << LucaSupport::Code.readable(credit_amount)
32
33
  f << []
33
34
  f << [d.dig('note')]
34
35
  end
35
36
  end
36
37
 
38
+ def self.update_codes(obj)
39
+ debit_code = serialize_on_key(obj[:debit], :code)
40
+ credit_code = serialize_on_key(obj[:credit], :code)
41
+ codes = (debit_code + credit_code).uniq.sort.compact
42
+ change_codes(obj[:id], codes)
43
+ end
44
+
37
45
  # define new transaction ID & write data at once
38
46
  def self.create_record!(date_obj, codes = nil)
39
47
  create_record(nil, date_obj, codes) do |f|
@@ -52,29 +60,25 @@ module LucaBook
52
60
  def self.load_data(io, path)
53
61
  {}.tap do |record|
54
62
  body = false
55
- record[:id] = path[0] + path[1]
63
+ record[:id] = "#{path[0]}/#{path[1]}"
56
64
  CSV.new(io, headers: false, col_sep: "\t", encoding: 'UTF-8')
57
65
  .each.with_index(0) do |line, i|
58
66
  case i
59
67
  when 0
60
68
  record[:debit] = line.map { |row| { code: row } }
61
69
  when 1
62
- line.each_with_index do |amount, i|
63
- record[:debit][i][:amount] = amount.to_i # TODO: bigdecimal support
64
- end
70
+ line.each_with_index { |amount, j| record[:debit][j][:amount] = BigDecimal(amount.to_s) }
65
71
  when 2
66
72
  record[:credit] = line.map { |row| { code: row } }
67
73
  when 3
68
- line.each_with_index do |amount, i|
69
- record[:credit][i][:amount] = amount.to_i # TODO: bigdecimal support
70
- end
74
+ line.each_with_index { |amount, j| record[:credit][j][:amount] = BigDecimal(amount.to_s) }
71
75
  else
72
- if line.empty?
76
+ if body == false && line.empty?
73
77
  record[:note] ||= []
74
78
  body = true
75
- next
79
+ else
80
+ record[:note] << line.join(' ') if body
76
81
  end
77
- record[:note] << line.join(' ') if body
78
82
  end
79
83
  record[:note]&.join('\n')
80
84
  end
@@ -6,13 +6,18 @@ require 'fileutils'
6
6
  module LucaBook
7
7
  class Setup
8
8
  # create project skeleton under specified directory
9
- def self.create_project(dir = LucaSupport::Config::Pjdir)
9
+ def self.create_project(country = nil, dir = LucaSupport::Config::Pjdir)
10
10
  FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
11
11
  Dir.chdir(dir) do
12
12
  %w[data/journals dict].each do |subdir|
13
13
  FileUtils.mkdir_p(subdir) unless Dir.exist?(subdir)
14
14
  end
15
- FileUtils.cp("#{__dir__}/templates/dict-en.tsv", 'dict/base.tsv') unless File.exist?('config.yml')
15
+ dict = if File.exist?("#{__dir__}/templates/dict-#{country}.tsv")
16
+ "dict-#{country}.tsv"
17
+ else
18
+ 'dict-en.tsv'
19
+ end
20
+ FileUtils.cp("#{__dir__}/templates/#{dict}", 'dict/base.tsv') unless File.exist?('dict/base.tsv')
16
21
  end
17
22
  end
18
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaBook
4
- VERSION = '0.2.11'
4
+ VERSION = '0.2.12'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucabook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
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-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord
@@ -87,7 +87,7 @@ files:
87
87
  - lib/luca_book/setup.rb
88
88
  - lib/luca_book/state.rb
89
89
  - lib/luca_book/templates/dict-en.tsv
90
- - lib/luca_book/templates/dict-ja.tsv
90
+ - lib/luca_book/templates/dict-jp.tsv
91
91
  - lib/luca_book/version.rb
92
92
  homepage: https://github.com/chumaltd/luca/tree/master/lucabook
93
93
  licenses: