Class: Sculd::Plan
- Inherits:
-
Object
- Object
- Sculd::Plan
- Defined in:
- lib/sculd/plan.rb
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
-
#datetime ⇒ Object
readonly
Returns the value of attribute datetime.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#flag_time ⇒ Object
readonly
Returns the value of attribute flag_time.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
Class Method Summary collapse
-
.parse(str, io = $stdout) ⇒ Object
Parse and return date, type, option.
- .wday(str) ⇒ Object
Instance Method Summary collapse
- #event_dates ⇒ Object
-
#initialize(datetime, flag_time, option, description) ⇒ Plan
constructor
A new instance of Plan.
-
#priority ⇒ Object
return priority of task calculated by equation defined in subclass.
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
#datetime ⇒ Object (readonly)
Returns the value of attribute datetime.
18 19 20 |
# File 'lib/sculd/plan.rb', line 18 def datetime @datetime end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
18 19 20 |
# File 'lib/sculd/plan.rb', line 18 def description @description end |
#flag_time ⇒ Object (readonly)
Returns the value of attribute flag_time.
18 19 20 |
# File 'lib/sculd/plan.rb', line 18 def flag_time @flag_time end |
#option ⇒ Object (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_dates ⇒ Object
89 90 91 |
# File 'lib/sculd/plan.rb', line 89 def event_dates raise NotDefinedError end |
#priority ⇒ Object
return priority of task calculated by equation defined in subclass.
85 86 87 |
# File 'lib/sculd/plan.rb', line 85 def priority raise NotDefinedError end |