Class: Editor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month) ⇒ Editor

Returns a new instance of Editor.


4
5
6
# File 'lib/editor.rb', line 4

def initialize(month)
  @month = month.full_month
end

Instance Attribute Details

#days_picked=(value) ⇒ Object

Sets the attribute days_picked

Parameters:

  • value

    the value to set the attribute days_picked to.


2
3
4
# File 'lib/editor.rb', line 2

def days_picked=(value)
  @days_picked = value
end

#monthObject

Returns the value of attribute month


2
3
4
# File 'lib/editor.rb', line 2

def month
  @month
end

Instance Method Details

#runObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/editor.rb', line 8

def run
  loop do
    print_month
    input = prompt
    exit if %w(q quit exit).include? input
    break if input == 'x'
    if days_picked?
      begin
        days_picked.each do |d|
          day = month.days[d - 1]
          blocks = input.strip.split(/\s+/).map do |block_str|
            BlockParser.parse block_str, day
          end
          day.add(*blocks)
        end
        reset!
      rescue
        next
      end
    else
      @days_picked = input.split(/,|\s+/).map!(&:to_i) unless input.empty?
    end
  end
rescue Interrupt, SystemExit
  exit
ensure
  month.cleanup!
  system 'clear'
end