class Codelog::CLIs::Interactive

Public Class Methods

new() click to toggle source
# File lib/codelog/clis/interactive.rb, line 9
def initialize
  @sections = YAML.load_file('changelogs/template.yml').keys
end

Public Instance Methods

ask_for_changes(changes = [], level = 1) click to toggle source
# File lib/codelog/clis/interactive.rb, line 35
def ask_for_changes(changes = [], level = 1)
  change = ask('>' * level)

  return changes if change.empty?

  change = { change.chomp(':') => ask_for_changes([], level + 1) } if subcategory?(change)

  ask_for_changes(changes.push(change), level)
end
ask_for_type() click to toggle source
# File lib/codelog/clis/interactive.rb, line 27
def ask_for_type
  say 'Enter a change type number:'
  @sections.each_with_index do |section, index|
    say "#{index + 1}. #{section}"
  end
  @sections[ask('>').to_i - 1]
end
run() click to toggle source
# File lib/codelog/clis/interactive.rb, line 13
def run
  changes_hash = Hash.new([])
  loop do
    change_category = ask_for_type
    say "\nType the entries for #{set_color(change_category, :yellow)}(ENTER to stop):"
    changes_hash[change_category] += ask_for_changes
    break if no? "\nWould you like to add a new log(Y|N)?"
  end

  changes_hash
end
subcategory?(change) click to toggle source
# File lib/codelog/clis/interactive.rb, line 45
def subcategory?(change)
  change.end_with?(':')
end