Class: TotalRecall::Helper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Helper

Returns a new instance of Helper.



14
15
16
# File 'lib/total_recall.rb', line 14

def initialize(config = {})
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/total_recall.rb', line 11

def config
  @config
end

#rowObject

Returns the value of attribute row.



12
13
14
# File 'lib/total_recall.rb', line 12

def row
  @row
end

Instance Method Details

#ask(question, &block) ⇒ Object



29
30
31
# File 'lib/total_recall.rb', line 29

def ask(question, &block)
  highline.ask(question, &block)
end

#ask_account(question, options = {}) ⇒ String

Prompts the user for an account-name.

Examples:

ask_account("What account did this money come from?",
            default: 'Expenses:Various')
What account did this money come from?  |Expenses:Various|
_

Parameters:

  • question (String)

    the question

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :default (String) — default: nil

    account-name that will be used if no input is provided.

Returns:

  • (String)

    the account-name



47
48
49
50
51
52
# File 'lib/total_recall.rb', line 47

def (question, options = {})
  options = { default: nil }.merge(options)
  highline.ask(question) do |q|
    q.default = options[:default] if options[:default]
  end
end

#highlineObject



25
26
27
# File 'lib/total_recall.rb', line 25

def highline
  @highline ||= HighLine.new($stdin, $stderr)
end

#render_row(options = {}) ⇒ Object



54
55
56
57
58
# File 'lib/total_recall.rb', line 54

def render_row(options = {})
  options = { columns: [] }.merge(options)
  _row = options[:columns].map{|i| row[i] }
  $stderr.puts Terminal::Table.new(rows: [ _row ])
end

#with_row(row, &block) ⇒ Object



18
19
20
21
22
23
# File 'lib/total_recall.rb', line 18

def with_row(row, &block)
  @row = row
  instance_eval(&block)
ensure
  @row = nil
end