Class: HledgerForecast::Forecast

Inherits:
Object
  • Object
show all
Defined in:
lib/hledger_forecast/forecast.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



3
4
5
# File 'lib/hledger_forecast/forecast.rb', line 3

def settings
  @settings
end

#transactionsObject (readonly)

Returns the value of attribute transactions.



3
4
5
# File 'lib/hledger_forecast/forecast.rb', line 3

def transactions
  @transactions
end

Class Method Details

.parse(csv_string, cli_options = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hledger_forecast/forecast.rb', line 5

def self.parse(csv_string, cli_options = nil)
  rows = CSV.parse(
    csv_string,
    headers: true,
    header_converters: -> (h) { h.to_s.tr("-", "_").to_sym },
    converters: :numeric
  )

  settings = Settings.parse(rows.select { |r| r[:type] == "settings" }, cli_options)

  transactions = []
  rows.each_with_index do |r, i|
    next if r[:type] == "settings"

    transactions << Transaction.from_row(r)
  rescue StandardError => e
    raise "CSV row #{i + 2}: #{e.message}"
  end

  new(transactions, settings, rows.headers.include?(:tag))
end

Instance Method Details

#has_tags_column?Boolean

Returns:

  • (Boolean)


27
# File 'lib/hledger_forecast/forecast.rb', line 27

def has_tags_column? = @has_tags_column