Class: Treasurer
- Inherits:
-
Object
show all
- Defined in:
- lib/treasurer/report.rb,
lib/treasurer.rb,
lib/treasurer/commands.rb
Overview
This seems obvious to me!!
Defined Under Namespace
Modules: LocalCustomisations
Classes: Reporter
Constant Summary
collapse
- SCRIPT_FOLDER =
File.dirname(File.expand_path(__FILE__))
Class Method Summary
collapse
Class Method Details
.add_file(file, account, copts = {}) ⇒ Object
4
5
6
7
8
|
# File 'lib/treasurer/commands.rb', line 4
def add_file(file, account, copts={})
load_treasurer_folder(copts)
ep 'entries', Dir.entries
CodeRunner.submit(p: "{data_file: '#{File.expand_path(file)}', account: :#{account}}")
end
|
.add_folder_of_files(folder, copts = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/treasurer/commands.rb', line 9
def add_folder_of_files(folder, copts={})
files = Dir.entries(folder).grep(/\.csv$/)
accounts = files.map{|f| f.sub(/\.csv/, '')}
files = files.map{|f| folder + '/' + f}
p ['files789', files, accounts]
files.zip(accounts).each{|f,a| add_file(f, a, copts)}
end
|
.assign(copts = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/treasurer/commands.rb', line 32
def assign(copts={})
load_treasurer_folder(copts)
crcopts = eval(copts[:C]||"{}")
crcopts[:h] = :component
crcopts[:O] = 'date'
crcopts[:f] = 'not (component_runs and component_runs.size > 0 and component_runs[0].instance_variable_get(:@external_account))'
crcopts[:f] = 'not (@external_account and @sub_account)'
catch (:quit_data_entry) do
CodeRunner.run_command('external_account', crcopts)
end
end
|
.check_is_treasurer_folder ⇒ Object
18
19
20
|
# File 'lib/treasurer/commands.rb', line 18
def check_is_treasurer_folder
raise "This folder has not been set up to use with Treasurer; please initialise a folder with treasurer init" unless FileTest.exist? '.code_runner_script_defaults.rb' and eval(File.read('.code_runner_script_defaults.rb'))[:code] == 'budget'
end
|
.create_report(copts = {}) ⇒ Object
21
22
23
24
|
# File 'lib/treasurer/commands.rb', line 21
def create_report(copts = {})
reporter = fetch_reporter(copts)
reporter.report()
end
|
.fetch_reporter(copts = {}) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/treasurer/commands.rb', line 25
def fetch_reporter(copts = {})
load_treasurer_folder(copts)
Reporter.new(
CodeRunner.fetch_runner(h: :component),
days_before: copts[:b]||360, days_ahead: copts[:a]||180,
today: copts[:t], report_currency: copts[:r])
end
|
.init_root_folder(folder, copts = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/treasurer/commands.rb', line 49
def init_root_folder(folder, copts={})
raise "Folder already exists" if FileTest.exist? folder
FileUtils.makedirs(folder)
FileUtils.cp(
SCRIPT_FOLDER + '/treasurer/local_customisations.rb',
folder + '/local_customisations.rb')
CodeRunner.fetch_runner(Y: folder, C: 'budget', X: '/dev/null')
init_sqlite(folder)
eputs "\n\n Your treasurer folder '#{folder}' has been set up. All further treasurer commands should be run from within this folder.\n"
end
|
.init_sqlite(folder) ⇒ Object
59
60
61
|
# File 'lib/treasurer/commands.rb', line 59
def init_sqlite(folder)
CodeRunner::Budget.init_sqlite(folder)
end
|
.list_last_updated(copts = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/treasurer/commands.rb', line 73
def list_last_updated(copts={})
reporter = fetch_reporter(copts)
reporter.generate_accounts
accts = reporter.accounts.find_all{|ac| not ac.external and not ac.type==:Equity}
puts "Account | Date "
accts.each do |ac|
puts "#{ac.name} | #{ac.runs.sort_by{|r| r.date}[-1].date.to_s}"
end
end
|
.load_treasurer_folder(copts = {}) ⇒ Object
.method_missing(meth, *args) ⇒ Object
84
85
86
|
# File 'lib/treasurer/commands.rb', line 84
def method_missing(meth, *args)
CodeRunner.send(meth, *args)
end
|
.setup(copts) ⇒ Object
This function gets called before every command and allows arbitrary manipulation of the command options (copts) hash
98
99
100
101
102
103
|
# File 'lib/treasurer.rb', line 98
def setup(copts)
copts[:t] = Date.parse(copts[:t]) if copts[:t]
end
|
.status(copts = {}) ⇒ Object
45
46
47
48
|
# File 'lib/treasurer/commands.rb', line 45
def status(copts={})
load_treasurer_folder(copts)
CodeRunner.status(eval(copts[:C]||"{}"))
end
|
.verbosity ⇒ Object
104
105
106
|
# File 'lib/treasurer.rb', line 104
def verbosity
2
end
|