Class: Sculd::Plan

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

Direct Known Subclasses

Deadline, Reminder, Schedule, Todo

Defined Under Namespace

Classes: Deadline, NotDefinedError, NotNumberError, NotWeekdayError, Reminder, Schedule, Todo, WeekdayMismatchError

Constant Summary collapse

REMINDER_PRIORITY =
10000
DEADLINE_PRIORITY =
20000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datetime, flag_time, option, description) ⇒ Plan

Returns a new instance of Plan.



77
78
79
80
81
82
# File 'lib/sculd/plan.rb', line 77

def initialize(datetime, flag_time, option, description)
    @datetime        = datetime
    @flag_time   = flag_time
    @option          =  option
    @description = description
end

Instance Attribute Details

#datetimeObject (readonly)

Returns the value of attribute datetime.



18
19
20
# File 'lib/sculd/plan.rb', line 18

def datetime
  @datetime
end

#descriptionObject (readonly)

Returns the value of attribute description.



18
19
20
# File 'lib/sculd/plan.rb', line 18

def description
  @description
end

#flag_timeObject (readonly)

Returns the value of attribute flag_time.



18
19
20
# File 'lib/sculd/plan.rb', line 18

def flag_time
  @flag_time
end

#optionObject (readonly)

Returns the value of attribute option.



18
19
20
# File 'lib/sculd/plan.rb', line 18

def option
  @option
end

Class Method Details

.parse(str, io = $stdout) ⇒ Object

Parse and return date, type, option.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sculd/plan.rb', line 24

def self.parse(str, io = $stdout)
    #/\[([\d\- :]*)\](.)(\S*)/ =~ str #OK
    /\[([^\]]*)\](.)(\S*)\s+(.*)/ =~ str #OK
    result = {}

    date, type, option, description = $1, $2, $3, $4

    datetime            = DateTime::parse date
    if /\((.+)\)/ =~ date
        unless self.wday($1) == datetime.wday
            io.puts "ERROR:"
            io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
            io.puts "but string contains #{date}."
            raise WeekdayMismatchError
        end
    end
    result[:datetime] = datetime
    result[:flag_time] = date.include?(":")

    result[:type]       = type

    unless option.empty?
        raise NotNumberError unless option =~ /^[0-9]+$/
        result[:option] = option.to_i 
    end

    result[:description] = description

    return result
end

.wday(str) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sculd/plan.rb', line 55

def self.wday(str)
    case str
    when /^Su/i
        return 0
    when /^M/i
        return 1
    when /^Tu/i
        return 2
    when /^W/i
        return 3
    when /^Th/i
        return 4
    when /^F/i
        return 5
    when /^Sa/i
        return 6
    else
        raise NotWeekdayError
    end
end

Instance Method Details

#event_datesObject

Raises:



89
90
91
# File 'lib/sculd/plan.rb', line 89

def event_dates
    raise NotDefinedError
end

#priorityObject

return priority of task calculated by equation defined in subclass.

Raises:



85
86
87
# File 'lib/sculd/plan.rb', line 85

def priority
    raise NotDefinedError
end