class HDOC::Progress

Provides methods for register and format user’s daily progress.

Constants

QUESTIONS

Attributes

record[R]

Public Class Methods

new(current_day) click to toggle source
# File lib/1hdoc/core/progress.rb, line 13
def initialize(current_day)
  @current_day = current_day
  @current_date = Time.now.strftime('%B %d, %Y')

  @record = {}
end

Public Instance Methods

format() click to toggle source
# File lib/1hdoc/core/progress.rb, line 34
def format
  result = "### Day #{@current_day}: #{@current_date}\n"
  record.each { |field, value| result << format_field(field, value) }

  result
end
format_field(field, value) click to toggle source
# File lib/1hdoc/core/progress.rb, line 41
def format_field(field, value)
  "**#{field.capitalize}:** #{value}\n\n"
end
register() click to toggle source
# File lib/1hdoc/core/progress.rb, line 20
def register
  $stderr.puts 'Finish your answer by typing :!'

  QUESTIONS.each do |field, question|
    $stderr.puts question
    @record[field] = ''

    while text_line = Readline.readline
      @record[field] += text_line.sub(':!', '') + "\n"
      break if text_line[':!']
    end
  end
end