Sha256: e9ecb98fb2438415c98801c7d52a9bdaa07f447beb1a71255c15d05e9ff2196c

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8

#require "sculd/plan/deadline.rb"
#require "sculd/plan/reminder.rb"
#require "sculd/plan/schedule.rb"
#require "sculd/plan/todo.rb"

#
#
#
class Sculd::Plan
  class NotDefinedError < Exception; end
  class WeekdayMismatchError < Exception; end
  class NotWeekdayError < Exception; end

  attr_reader :description

  REMINDER_PRIORITY = 10000
  DEADLINE_PRIORITY = 20000

  # Parse and return date, type, option.
  def self.parse(str, io = $stdout)
    #/\[([\d\- :]*)\](.)(\S*)/ =~ str #OK
    /\[([^\]]*)\](.)(\S*)/ =~ str #OK

    datestr = $1
    type    = $2
    option  = $3.to_s

    datetime      = DateTime::parse datestr
    if /\((.+)\)/ =~ datestr
      #pp $1
      #pp datetime.wday
      #pp self.wday($1)
      unless self.wday($1) == datetime.wday
        #io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
        #io.puts "but string contains #{datestr}."
        io.puts "ERROR:"
        io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
        io.puts "but string contains #{datestr}."
        raise WeekdayMismatchError
      end
    end
    return datetime, type, option
  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
    end
  end

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

  # return priority of task calculated by equation defined in subclass. 
  def priority
    raise NotDefinedError
  end

  def events
    raise NotDefinedError
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sculd-0.0.3 lib/sculd/plan.rb
sculd-0.0.2 lib/sculd/plan.rb