Class: LucaBookConsole
- Inherits:
-
Object
- Object
- LucaBookConsole
- Defined in:
- lib/luca_book/console.rb
Overview
This class will be deleted
Instance Method Summary collapse
-
#bs ⇒ Object
TODO: deprecated.
- #by_term(year, month, end_year = year, end_month = month) ⇒ Object
- #cnsl_bold(str) ⇒ Object
- #cnsl_code(obj) ⇒ Object
- #cnsl_fmt(str, width = 15, length = nil) ⇒ Object
- #cnsl_label(label, code) ⇒ Object
- #convert_collection(obj) ⇒ Object
-
#initialize(dir_path = nil) ⇒ LucaBookConsole
constructor
A new instance of LucaBookConsole.
-
#pl ⇒ Object
TODO: deprecated.
- #show_records(records) ⇒ Object
Constructor Details
#initialize(dir_path = nil) ⇒ LucaBookConsole
Returns a new instance of LucaBookConsole.
7 8 9 |
# File 'lib/luca_book/console.rb', line 7 def initialize(dir_path=nil) @report = LucaBook::State.new(dir_path) end |
Instance Method Details
#bs ⇒ Object
TODO: deprecated. accumulate_all() already removed.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/luca_book/console.rb', line 33 def bs target = [] report = [] output = @report.accumulate_all do |f| target << f[:target] report << f[:current] #diff << f[:diff] end puts "---- BS ----" target.each_slice(6) do |v| puts "#{cnsl_fmt("", 14)} #{v.map{|v| cnsl_fmt(v, 14)}.join}" end convert_collection(report).each do |h| if /^[0-9]/.match(h[:code]) if /[^0]$/.match(h[:code]) print " " print " " if h[:code].length > 3 end puts cnsl_label(h[:label], h[:code]) h[:amount].each_slice(6) do |v| puts "#{cnsl_fmt("", 14)} #{v.map{|v| cnsl_fmt(v, 14)}.join}" end end end puts "---- ----" end |
#by_term(year, month, end_year = year, end_month = month) ⇒ Object
11 12 13 14 |
# File 'lib/luca_book/console.rb', line 11 def by_term(year, month, end_year = year, end_month = month) array = @report.book.class.term(year, month, end_year, end_month) show_records(array) end |
#cnsl_bold(str) ⇒ Object
113 114 115 |
# File 'lib/luca_book/console.rb', line 113 def cnsl_bold(str) "\e[1m#{str}\e[0m" end |
#cnsl_code(obj) ⇒ Object
117 118 119 |
# File 'lib/luca_book/console.rb', line 117 def cnsl_code(obj) code = @report.dict.dig(obj&.dig(:code))&.dig(:label) || "" end |
#cnsl_fmt(str, width = 15, length = nil) ⇒ Object
121 122 123 124 |
# File 'lib/luca_book/console.rb', line 121 def cnsl_fmt(str, width=15, length=nil) length ||= width sprintf("%#{width}.#{length}s", str) end |
#cnsl_label(label, code) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/luca_book/console.rb', line 105 def cnsl_label(label, code) if /[0]$/.match(code) cnsl_bold(label) + " " + "-"*80 else label end end |
#convert_collection(obj) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/luca_book/console.rb', line 89 def convert_collection(obj) {}.tap {|res| obj.each do |month| month.each do |k,v| if res.has_key?(k) res[k] << v else res[k] = [v] end end end }.sort.map do |k,v| {code: k, label: @report.dict.dig(k, :label), amount: v} end end |
#pl ⇒ Object
TODO: deprecated. accumulate_all() already removed.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/luca_book/console.rb', line 61 def pl target = [] report = [] output = @report.accumulate_all do |f| target << f[:target] report << f[:diff] #current << f[:current] end puts "---- PL ----" target.each_slice(6) do |v| puts "#{cnsl_fmt("", 14)} #{v.map{|v| cnsl_fmt(v, 14)}.join}" end convert_collection(report).each do |h| if /^[A-Z]/.match(h[:code]) total = [h[:amount].inject(:+)] + Array.new(h[:amount].length) if /[^0]$/.match(h[:code]) print " " print " " if h[:code].length > 3 end puts cnsl_label(h[:label], h[:code]) h[:amount].each_slice(6).with_index(0) do |v, i| puts "#{cnsl_fmt(total[i], 14)} #{v.map{|v| cnsl_fmt(v, 14)}.join}" end end end puts "---- ----" end |
#show_records(records) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/luca_book/console.rb', line 16 def show_records(records) print "#{cnsl_fmt("ID")} #{cnsl_fmt("debit")} #{cnsl_fmt("credit")} #{cnsl_fmt("")*2}" print "#{cnsl_fmt("balance")}" unless records.first.dig(:balance).nil? puts records.each do |h| puts "#{cnsl_fmt(h.dig(:id))} #{"-"*85}" lines = [h.dig(:debit)&.length, h.dig(:credit)&.length]&.max || 0 lines.times do |i| puts "#{cnsl_fmt("")} #{cnsl_fmt(h.dig(:debit, i, :amount))} #{cnsl_code(h.dig(:debit, i))}" if h.dig(:debit, i, :amount) puts "#{cnsl_fmt("")*2} #{cnsl_fmt(h.dig(:credit, i, :amount))} #{cnsl_code(h.dig(:credit, i))}" if h.dig(:credit, i, :amount) end puts "#{cnsl_fmt(""*15)*5} #{cnsl_fmt(h.dig(:balance))}" unless h.dig(:balance).nil? puts "#{cnsl_fmt(""*15)} #{h.dig(:note)}" end end |