Class: Sculd::Manager

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

Defined Under Namespace

Classes: ArgumentError, LoadError

Constant Summary collapse

DEFAULT_WEEKDAYS =
[ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, io = $stdout) ⇒ Manager

Returns a new instance of Manager.



20
21
22
23
24
25
26
27
# File 'lib/sculd/manager.rb', line 20

def initialize(dir, io = $stdout)
  @source_dir = dir
  @weekdays = DEFAULT_WEEKDAYS
  @plans = []
  Dir.glob("#{@source_dir}/*").each do |file|
    load_file(file, io)
  end
end

Instance Attribute Details

#weekdaysObject (readonly)

Returns the value of attribute weekdays.



13
14
15
# File 'lib/sculd/manager.rb', line 13

def weekdays
  @weekdays
end

Instance Method Details

#set_weekdays(ary) ⇒ Object



29
30
31
32
33
34
# File 'lib/sculd/manager.rb', line 29

def set_weekdays(ary)
  unless ary.size == 7
    raise ArgumentError, ary.to_s
  end
  @weekdays = ary
end

#show_events(dates, io = $stdout) ⇒ Object

Show events in ‘num’ days from todary. def show_events(num, today = Date.today, io = $stdout)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sculd/manager.rb', line 43

def show_events(dates, io = $stdout)
  hl = HighLine.new($stdin, io)

  d_e = days_events
  io.puts "Events:"
  dates.each do |date|
    str = " #{date.to_s} #{@weekdays[date.wday]} "

    case date.wday
    when 0
      fgcolor = ":white"; bgcolor = ":on_red";
    when 6
      fgcolor = ":white"; bgcolor = ":on_blue";
    else
      fgcolor = ":black"; bgcolor = ":on_white";
    end
    hl.say("  <%= color('#{str}', #{fgcolor}, #{bgcolor}) %>\n")

    events = d_e[date]
    if events # if plan is not empty.
      events.sort_by{|j| j.datetime}.each do |event|

        io.print("    ") #indent
        event_date = Date.new(event.datetime.year,
                              event.datetime.month,
                              event.datetime.day)
        if event_date != date
          io.printf("<%02d/%02d>", event.datetime.month, event.datetime.day )
        elsif event.flag_time
          io.printf("[%02d:%02d]", event.datetime.hour, event.datetime.minute )
        else
          io.print("       ")
        end
        io.printf("%s", event.class::SYMBOL_CHAR )
        io.printf("%-2s ", event.option.to_s )
        io.puts "#{event.description}"
      end
    else
      io.puts "        (no event)"
    end
    io.puts
  end
end

#show_tasks(num, today = Date.today, io = $stdout) ⇒ Object

Show ‘num’ tasks of the highest priority.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sculd/manager.rb', line 88

def show_tasks(num, today = Date.today, io = $stdout)
  return if num == 0

  io.puts "Tasks:"
  plans = @plans.sort_by {|plan| plan.priority(today)}.reverse

  num = plans.size if plans.size < num
  plans[0..(num-1)].each do |plan|
    io.printf("  [%4d-%02d-%02d]",
      plan.datetime.year,
      plan.datetime.month,
      plan.datetime.day,
            )
    io.printf("%s%-2s %s",
      plan.class::SYMBOL_CHAR,
      plan.option.to_s,
      plan.description
    #io.print "  #{plan.description.strip}"
    )
    io.puts
  end
end