Class: LucaBook::Setup
- Inherits:
-
Object
- Object
- LucaBook::Setup
- Defined in:
- lib/luca_book/setup.rb
Class Method Summary collapse
-
.create_project(country = nil, dir = LucaSupport::CONST.pjdir) ⇒ Object
create project skeleton under specified directory.
-
.prepare_starttsv(dict) ⇒ Object
Generate initial balance template.
Class Method Details
.create_project(country = nil, dir = LucaSupport::CONST.pjdir) ⇒ Object
create project skeleton under specified directory
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/luca_book/setup.rb', line 9 def self.create_project(country = nil, dir = LucaSupport::CONST.pjdir) FileUtils.mkdir_p(dir) unless Dir.exist?(dir) Dir.chdir(dir) do %w[data/journals data/balance dict].each do |subdir| FileUtils.mkdir_p(subdir) unless Dir.exist?(subdir) end dict = if File.exist?("#{__dir__}/templates/dict-#{country}.tsv") "dict-#{country}.tsv" else 'dict-en.tsv' end FileUtils.cp("#{__dir__}/templates/#{dict}", 'dict/base.tsv') unless File.exist?('dict/base.tsv') FileUtils.cp("#{__dir__}/templates/config.yml", 'config.yml') unless File.exist?('config.yml') exdict = if File.exist?("#{__dir__}/templates/dictex-#{country}.tsv") "dict-#{country}.tsv" else nil end FileUtils.cp("#{__dir__}/templates/#{exdict}", 'dict/ext.tsv') unless (File.exist?('dict/ext.tsv') || exdict.nil?) prepare_starttsv(dict) unless File.exist? 'data/balance/start.tsv' end end |
.prepare_starttsv(dict) ⇒ Object
Generate initial balance template. Codes are same as base dictionary. The previous month of start date is better for _date.
36 37 38 39 40 41 42 43 44 |
# File 'lib/luca_book/setup.rb', line 36 def self.prepare_starttsv(dict) CSV.open('data/balance/start.tsv', 'w', col_sep: "\t", encoding: 'UTF-8') do |csv| csv << ['code', 'label', 'balance'] csv << ['_date', '2020-1-1'] CSV.open("#{__dir__}/templates/#{dict}", 'r', col_sep: "\t", encoding: 'UTF-8').each do |row| csv << row[0, 1] if /^[1-9]/.match(row[0]) end end end |