Class: HDOC::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/1hdoc/core/progress.rb

Overview

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

Constant Summary collapse

QUESTIONS =
{
  progress: 'Your progress: ',
  thoughts: 'Your thoughts: ',
  link: 'Link to work: '
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_day) ⇒ Progress

Returns a new instance of Progress.



13
14
15
16
17
18
# 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

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



5
6
7
# File 'lib/1hdoc/core/progress.rb', line 5

def record
  @record
end

Instance Method Details

#formatObject



34
35
36
37
38
39
# 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) ⇒ Object



41
42
43
# File 'lib/1hdoc/core/progress.rb', line 41

def format_field(field, value)
  "**#{field.capitalize}:** #{value}\n\n"
end

#registerObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# 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