Module: Hab::Formatter::ClassMethods

Included in:
Hab::Formatter
Defined in:
lib/hab/formatter.rb

Instance Method Summary collapse

Instance Method Details

#stats(stats) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hab/formatter.rb', line 28

def stats(stats)
  <<-BLOCK
HP #{stats.hp}
MAX_HP #{stats.max_health}
MP #{stats.mp}
MAX_MP #{stats.max_mp}
EXP #{stats.exp}
TO_NEXT_LEVEL #{stats.to_next_level}
PER #{stats.per}
INT #{stats.int}
CON #{stats.con}
STR #{stats.str}
LVL #{stats.lvl}
GP #{stats.gp}
BLOCK
end

#status(user) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hab/formatter.rb', line 13

def status(user)
  stats = user.stats
  dailies = user.tasks.dailies
  todos = user.tasks.todos
  dailies_complete_count = dailies.count(&:completed?)
  todos_complete_count = todos.count(&:completed?)
  <<-BLOCK
#{statbar(:HP, stats.hp, stats.max_health)}
#{statbar(:EXP, stats.exp, stats.to_next_level)}
#{statbar(:MP, stats.mp, stats.max_mp)}
#{statbar(:DAILIES, dailies_complete_count, dailies.count)}
#{statbar(:TODOS, todos_complete_count, todos.count)}
BLOCK
end

#task(task, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hab/formatter.rb', line 49

def task(task, options = {})
  if options[:emoji] == true
    Rumoji
      .decode(task.text)
      .colorize(value_color(task.value))
  else
    Rumoji
      .erase(task.text)
      .gsub(/\ \ /, ' ')
      .strip
      .colorize(value_color(task.value))
  end

end

#tasks(tasks, options = {}) ⇒ Object



45
46
47
# File 'lib/hab/formatter.rb', line 45

def tasks(tasks, options = {})
  tasks.map { |task| task(task, options) }.join("\n")
end