Sha256: 57c1608a0dff8654f4cf346e271d9384936fe705a312e4a9580faf0d99a67bb2
Contents?: true
Size: 1.89 KB
Versions: 3
Compression:
Stored size: 1.89 KB
Contents
#! /usr/bin/env ruby # coding: utf-8 # # # class Sculd::Plan class NotDefinedError < Exception; end class WeekdayMismatchError < Exception; end class NotWeekdayError < Exception; end class NotNumberError < Exception; end attr_reader :description, :flag_time, :datetime, :option REMINDER_PRIORITY = 10000 DEADLINE_PRIORITY = 20000 # Parse and return date, type, option. 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 weekday = self.wday($1) unless weekday == datetime.wday raise WeekdayMismatchError, "#{datetime} is #{Sculd::Manager::DEFAULT_WEEKDAYS[datetime.wday]}, but string contains #{date}." 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 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, "Unknown format string: #{str}" end end # def initialize(datetime, flag_time, option, description) @datetime = datetime @flag_time = flag_time @option = option @description = description end # return priority of task calculated by equation defined in subclass. def priority raise NotDefinedError end def event_dates raise NotDefinedError end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sculd-0.2.2 | lib/sculd/plan.rb |
sculd-0.2.1 | lib/sculd/plan.rb |
sculd-0.2.0 | lib/sculd/plan.rb |