sculd 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/sculd/plan.rb CHANGED
@@ -1,93 +1,87 @@
1
1
  #! /usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
- #require "sculd/plan/deadline.rb"
5
- #require "sculd/plan/reminder.rb"
6
- #require "sculd/plan/schedule.rb"
7
- #require "sculd/plan/todo.rb"
8
-
9
4
  #
10
5
  #
11
6
  #
12
7
  class Sculd::Plan
13
- class NotDefinedError < Exception; end
14
- class WeekdayMismatchError < Exception; end
15
- class NotWeekdayError < Exception; end
16
- class NotNumberError < Exception; end
17
-
18
- attr_reader :description, :flag_time, :datetime, :option
19
-
20
- REMINDER_PRIORITY = 10000
21
- DEADLINE_PRIORITY = 20000
22
-
23
- # Parse and return date, type, option.
24
- def self.parse(str, io = $stdout)
25
- #/\[([\d\- :]*)\](.)(\S*)/ =~ str #OK
26
- /\[([^\]]*)\](.)(\S*)\s+(.*)/ =~ str #OK
27
- result = {}
28
-
29
- date, type, option, description = $1, $2, $3, $4
30
-
31
- datetime = DateTime::parse date
32
- if /\((.+)\)/ =~ date
33
- unless self.wday($1) == datetime.wday
34
- io.puts "ERROR:"
35
- io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
36
- io.puts "but string contains #{date}."
37
- raise WeekdayMismatchError
38
- end
39
- end
40
- result[:datetime] = datetime
41
- result[:flag_time] = date.include?(":")
42
-
43
- result[:type] = type
44
-
45
- unless option.empty?
46
- raise NotNumberError unless option =~ /^[0-9]+$/
47
- result[:option] = option.to_i
48
- end
49
-
50
- result[:description] = description
51
-
52
- return result
8
+ class NotDefinedError < Exception; end
9
+ class WeekdayMismatchError < Exception; end
10
+ class NotWeekdayError < Exception; end
11
+ class NotNumberError < Exception; end
12
+
13
+ attr_reader :description, :flag_time, :datetime, :option
14
+
15
+ REMINDER_PRIORITY = 10000
16
+ DEADLINE_PRIORITY = 20000
17
+
18
+ # Parse and return date, type, option.
19
+ def self.parse(str, io = $stdout)
20
+ #/\[([\d\- :]*)\](.)(\S*)/ =~ str #OK
21
+ /\[([^\]]*)\](.)(\S*)\s+(.*)/ =~ str #OK
22
+ result = {}
23
+
24
+ date, type, option, description = $1, $2, $3, $4
25
+
26
+ datetime = DateTime::parse date
27
+ if /\((.+)\)/ =~ date
28
+ weekday = self.wday($1)
29
+ unless weekday == datetime.wday
30
+ raise WeekdayMismatchError,
31
+ "#{datetime} is #{Sculd::Manager::DEFAULT_WEEKDAYS[datetime.wday]}, but string contains #{date}."
32
+ end
53
33
  end
34
+ result[:datetime] = datetime
35
+ result[:flag_time] = date.include?(":")
54
36
 
55
- def self.wday(str)
56
- case str
57
- when /^Su/i
58
- return 0
59
- when /^M/i
60
- return 1
61
- when /^Tu/i
62
- return 2
63
- when /^W/i
64
- return 3
65
- when /^Th/i
66
- return 4
67
- when /^F/i
68
- return 5
69
- when /^Sa/i
70
- return 6
71
- else
72
- raise NotWeekdayError
73
- end
74
- end
75
-
76
- #
77
- def initialize(datetime, flag_time, option, description)
78
- @datetime = datetime
79
- @flag_time = flag_time
80
- @option = option
81
- @description = description
82
- end
37
+ result[:type] = type
83
38
 
84
- # return priority of task calculated by equation defined in subclass.
85
- def priority
86
- raise NotDefinedError
39
+ unless option.empty?
40
+ raise NotNumberError unless option =~ /^[0-9]+$/
41
+ result[:option] = option.to_i
87
42
  end
88
43
 
89
- def event_dates
90
- raise NotDefinedError
44
+ result[:description] = description
45
+
46
+ return result
47
+ end
48
+
49
+ def self.wday(str)
50
+ case str
51
+ when /^Su/i , '日'
52
+ return 0
53
+ when /^M/i , '月'
54
+ return 1
55
+ when /^Tu/i , '火'
56
+ return 2
57
+ when /^W/i , '水'
58
+ return 3
59
+ when /^Th/i , '木'
60
+ return 4
61
+ when /^F/i , '金'
62
+ return 5
63
+ when /^Sa/i , '土'
64
+ return 6
65
+ else
66
+ raise NotWeekdayError, "Unknown format string: #{str}"
91
67
  end
68
+ end
69
+
70
+ #
71
+ def initialize(datetime, flag_time, option, description)
72
+ @datetime = datetime
73
+ @flag_time = flag_time
74
+ @option = option
75
+ @description = description
76
+ end
77
+
78
+ # return priority of task calculated by equation defined in subclass.
79
+ def priority
80
+ raise NotDefinedError
81
+ end
82
+
83
+ def event_dates
84
+ raise NotDefinedError
85
+ end
92
86
  end
93
87
 
@@ -9,37 +9,37 @@
9
9
  #
10
10
  class Sculd::Plan::Deadline < Sculd::Plan
11
11
 
12
- SYMBOL_CHAR = "!"
13
- DEFAULT_OPTION = 7
12
+ SYMBOL_CHAR = "!"
13
+ DEFAULT_OPTION = 7
14
14
 
15
- def priority(today)
16
- #pp @option
17
- #@option = 1 if @option < 1
18
- option = (@option || DEFAULT_OPTION)
19
- beginning = @datetime - option
20
- #pp beginning
21
- if today < beginning
22
- return 0
23
- elsif today == @datetime
24
- return Sculd::Plan::DEADLINE_PRIORITY
25
- elsif today <= @datetime
26
- rp = Sculd::Plan::REMINDER_PRIORITY
27
- dp = Sculd::Plan::DEADLINE_PRIORITY
28
- return (rp + (dp - rp) * (today - beginning)/(option.to_f)).to_i
29
- else
30
- return Sculd::Plan::DEADLINE_PRIORITY
31
- end
15
+ def priority(today)
16
+ #pp @option
17
+ #@option = 1 if @option < 1
18
+ option = (@option || DEFAULT_OPTION)
19
+ beginning = @datetime - option
20
+ #pp beginning
21
+ if today < beginning
22
+ return 0
23
+ elsif today == @datetime
24
+ return Sculd::Plan::DEADLINE_PRIORITY
25
+ elsif today <= @datetime
26
+ rp = Sculd::Plan::REMINDER_PRIORITY
27
+ dp = Sculd::Plan::DEADLINE_PRIORITY
28
+ return (rp + (dp - rp) * (today - beginning)/(option.to_f)).to_i
29
+ else
30
+ return Sculd::Plan::DEADLINE_PRIORITY
32
31
  end
32
+ end
33
33
 
34
- def event_dates
35
- #@option ||= DEFAULT_OPTION
34
+ def event_dates
35
+ #@option ||= DEFAULT_OPTION
36
36
 
37
- results = []
38
- results << @datetime - (@option || DEFAULT_OPTION) unless @option == 0
39
- results << @datetime
40
- results.map do |datetime|
41
- Date.new(datetime.year, datetime.month, datetime.day)
42
- end
37
+ results = []
38
+ results << @datetime - (@option || DEFAULT_OPTION) unless @option == 0
39
+ results << @datetime
40
+ results.map do |datetime|
41
+ Date.new(datetime.year, datetime.month, datetime.day)
43
42
  end
43
+ end
44
44
  end
45
45
 
@@ -9,20 +9,20 @@
9
9
  #
10
10
  class Sculd::Plan::Reminder < Sculd::Plan
11
11
 
12
- SYMBOL_CHAR = "-"
12
+ SYMBOL_CHAR = "-"
13
13
 
14
- # value of @option does not work
15
- def priority(today = Date.now)
16
- if today < @datetime
17
- return 0
18
- else
19
- #@option = 1 if @option < 1
20
- return Sculd::Plan::REMINDER_PRIORITY - (today - @datetime) #/@option
21
- end
14
+ # value of @option does not work
15
+ def priority(today = Date.now)
16
+ if today < @datetime
17
+ return 0
18
+ else
19
+ #@option = 1 if @option < 1
20
+ return Sculd::Plan::REMINDER_PRIORITY - (today - @datetime) #/@option
22
21
  end
22
+ end
23
23
 
24
- def event_dates
25
- [Date.new(@datetime.year, @datetime.month, @datetime.day)]
26
- end
24
+ def event_dates
25
+ [Date.new(@datetime.year, @datetime.month, @datetime.day)]
26
+ end
27
27
  end
28
28
 
@@ -8,15 +8,15 @@
8
8
  #
9
9
  class Sculd::Plan::Schedule < Sculd::Plan
10
10
 
11
- SYMBOL_CHAR = "@"
11
+ SYMBOL_CHAR = "@"
12
12
 
13
- #
14
- def priority(today = Date.new)
15
- return 0
16
- end
13
+ #
14
+ def priority(today = Date.new)
15
+ return 0
16
+ end
17
17
 
18
- def event_dates
19
- [Date.new(@datetime.year, @datetime.month, @datetime.day)]
20
- end
18
+ def event_dates
19
+ [Date.new(@datetime.year, @datetime.month, @datetime.day)]
20
+ end
21
21
  end
22
22
 
@@ -9,35 +9,35 @@
9
9
  #
10
10
  class Sculd::Plan::Todo < Sculd::Plan
11
11
 
12
- SYMBOL_CHAR = "+"
13
- DEFAULT_OPTION = 7
12
+ SYMBOL_CHAR = "+"
13
+ DEFAULT_OPTION = 7
14
14
 
15
- #
16
- def priority(today)
17
- #@option = 1 if @option < 1
18
- option = @option || DEFAULT_OPTION
19
- beginning = @datetime
20
- ending = @datetime + option
21
- if today < beginning
22
- return 0
23
- elsif today <= ending
24
- rp = Sculd::Plan::REMINDER_PRIORITY
25
- dp = Sculd::Plan::DEADLINE_PRIORITY
26
- return (rp + (dp - rp) * (today - beginning)/(option.to_f)).to_i
27
- else
28
- return Sculd::Plan::DEADLINE_PRIORITY
29
- end
15
+ #
16
+ def priority(today)
17
+ #@option = 1 if @option < 1
18
+ option = @option || DEFAULT_OPTION
19
+ beginning = @datetime
20
+ ending = @datetime + option
21
+ if today < beginning
22
+ return 0
23
+ elsif today <= ending
24
+ rp = Sculd::Plan::REMINDER_PRIORITY
25
+ dp = Sculd::Plan::DEADLINE_PRIORITY
26
+ return (rp + (dp - rp) * (today - beginning)/(option.to_f)).to_i
27
+ else
28
+ return Sculd::Plan::DEADLINE_PRIORITY
30
29
  end
30
+ end
31
31
 
32
- def event_dates
33
- #@option ||= DEFAULT_OPTION
32
+ def event_dates
33
+ #@option ||= DEFAULT_OPTION
34
34
 
35
- results = []
36
- results << @datetime
37
- results << @datetime + (@option || DEFAULT_OPTION)
38
- results.map do |datetime|
39
- Date.new(datetime.year, datetime.month, datetime.day)
40
- end
35
+ results = []
36
+ results << @datetime
37
+ results << @datetime + (@option || DEFAULT_OPTION)
38
+ results.map do |datetime|
39
+ Date.new(datetime.year, datetime.month, datetime.day)
41
40
  end
41
+ end
42
42
  end
43
43
 
data/sculd.gemspec CHANGED
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: sculd 0.2.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "sculd"
8
- s.version = "0.1.3"
9
+ s.version = "0.2.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["ippei94da"]
12
- s.date = "2014-08-29"
14
+ s.date = "2017-04-24"
13
15
  s.description = "Schedule management system using 'howm' like format. Plans, i.e., schedule(@), reminder(-), deadline(!), and tood(+), make events and tasks. Command 'sculd' can output events on each date and tasks with high priority. "
14
16
  s.email = "ippei94da@gmail.com"
15
17
  s.executables = ["dates", "sculd"]
@@ -50,32 +52,34 @@ Gem::Specification.new do |s|
50
52
  ]
51
53
  s.homepage = "http://github.com/ippei94da/sculd"
52
54
  s.licenses = ["MIT"]
53
- s.require_paths = ["lib"]
54
- s.rubygems_version = "1.8.23"
55
+ s.rubygems_version = "2.5.1"
55
56
  s.summary = "Sculd, SChedULe Dealer."
56
57
 
57
58
  if s.respond_to? :specification_version then
58
- s.specification_version = 3
59
+ s.specification_version = 4
59
60
 
60
61
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
- s.add_development_dependency(%q<rdoc>, ["~> 4.1.1"])
62
- s.add_development_dependency(%q<bundler>, ["~> 1.7.2"])
63
- s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
64
- s.add_development_dependency(%q<simplecov>, [">= 0.8.2"])
65
- s.add_development_dependency(%q<highline>, [">= 1.6.21"])
62
+ s.add_development_dependency(%q<test-unit>, ["~> 3.2"])
63
+ s.add_development_dependency(%q<rdoc>, ["~> 4.2"])
64
+ s.add_development_dependency(%q<bundler>, ["~> 1.11"])
65
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
66
+ s.add_development_dependency(%q<simplecov>, ["~> 0.11"])
67
+ s.add_development_dependency(%q<highline>, ["~> 1.6"])
66
68
  else
67
- s.add_dependency(%q<rdoc>, ["~> 4.1.1"])
68
- s.add_dependency(%q<bundler>, ["~> 1.7.2"])
69
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
70
- s.add_dependency(%q<simplecov>, [">= 0.8.2"])
71
- s.add_dependency(%q<highline>, [">= 1.6.21"])
69
+ s.add_dependency(%q<test-unit>, ["~> 3.2"])
70
+ s.add_dependency(%q<rdoc>, ["~> 4.2"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.11"])
72
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
73
+ s.add_dependency(%q<simplecov>, ["~> 0.11"])
74
+ s.add_dependency(%q<highline>, ["~> 1.6"])
72
75
  end
73
76
  else
74
- s.add_dependency(%q<rdoc>, ["~> 4.1.1"])
75
- s.add_dependency(%q<bundler>, ["~> 1.7.2"])
76
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
77
- s.add_dependency(%q<simplecov>, [">= 0.8.2"])
78
- s.add_dependency(%q<highline>, [">= 1.6.21"])
77
+ s.add_dependency(%q<test-unit>, ["~> 3.2"])
78
+ s.add_dependency(%q<rdoc>, ["~> 4.2"])
79
+ s.add_dependency(%q<bundler>, ["~> 1.11"])
80
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
81
+ s.add_dependency(%q<simplecov>, ["~> 0.11"])
82
+ s.add_dependency(%q<highline>, ["~> 1.6"])
79
83
  end
80
84
  end
81
85
 
data/test/helper.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
  begin
4
- Bundler.setup(:default, :development)
4
+ Bundler.setup(:default, :development)
5
5
  rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
9
  end
10
10
  require 'test/unit'
11
11
 
@@ -4,71 +4,71 @@
4
4
  require "helper"
5
5
 
6
6
  class TC_Deadline < Test::Unit::TestCase
7
- def setup
8
- date = Date.new(2012, 10, 15)
9
- @d00 = Sculd::Plan::Deadline.new(date, false, 10, 'deadlineA')
7
+ def setup
8
+ date = Date.new(2012, 10, 15)
9
+ @d00 = Sculd::Plan::Deadline.new(date, false, 10, 'deadlineA')
10
10
 
11
- date = DateTime.new(2012, 10, 15, 23, 45, 00)
12
- @d01 = Sculd::Plan::Deadline.new(date, false, 10, 'deadlineA')
11
+ date = DateTime.new(2012, 10, 15, 23, 45, 00)
12
+ @d01 = Sculd::Plan::Deadline.new(date, false, 10, 'deadlineA')
13
13
 
14
- date = Date.new(2012, 10, 15)
15
- @d02 = Sculd::Plan::Deadline.new(date, false, nil, 'deadlineA')
14
+ date = Date.new(2012, 10, 15)
15
+ @d02 = Sculd::Plan::Deadline.new(date, false, nil, 'deadlineA')
16
16
 
17
- date = Date.new(2012, 10, 15)
18
- @d03 = Sculd::Plan::Deadline.new(date, false, 0, 'deadlineA')
17
+ date = Date.new(2012, 10, 15)
18
+ @d03 = Sculd::Plan::Deadline.new(date, false, 0, 'deadlineA')
19
19
 
20
- end
20
+ end
21
21
 
22
- #context 'Date[2012-10-15], 10, [2012-10-15]!10 deadlineA' do
22
+ #context 'Date[2012-10-15], 10, [2012-10-15]!10 deadlineA' do
23
23
 
24
- def test_priority
25
- today = Date.new(2012, 10, 15)
26
- assert_equal(20000, @d00.priority(today))
24
+ def test_priority
25
+ today = Date.new(2012, 10, 15)
26
+ assert_equal(20000, @d00.priority(today))
27
27
 
28
- today = Date.new(2012, 10, 20)
29
- assert_equal(20000, @d00.priority(today))
28
+ today = Date.new(2012, 10, 20)
29
+ assert_equal(20000, @d00.priority(today))
30
30
 
31
- today = Date.new(2012, 10, 10)
32
- assert_equal(15000, @d00.priority(today))
31
+ today = Date.new(2012, 10, 10)
32
+ assert_equal(15000, @d00.priority(today))
33
33
 
34
- today = Date.new(2012, 10, 1)
35
- assert_equal(0, @d00.priority(today))
34
+ today = Date.new(2012, 10, 1)
35
+ assert_equal(0, @d00.priority(today))
36
36
 
37
37
 
38
- today = Date.new(2012, 10, 1)
39
- assert_equal( 0, @d02.priority(today))
38
+ today = Date.new(2012, 10, 1)
39
+ assert_equal( 0, @d02.priority(today))
40
40
 
41
- today = Date.new(2012, 10, 8)
42
- assert_equal(10000, @d02.priority(today))
41
+ today = Date.new(2012, 10, 8)
42
+ assert_equal(10000, @d02.priority(today))
43
43
 
44
- today = Date.new(2012, 10, 10)
45
- assert_equal(12857, @d02.priority(today))
44
+ today = Date.new(2012, 10, 10)
45
+ assert_equal(12857, @d02.priority(today))
46
46
 
47
- today = Date.new(2012, 10, 15)
48
- assert_equal(20000, @d02.priority(today))
47
+ today = Date.new(2012, 10, 15)
48
+ assert_equal(20000, @d02.priority(today))
49
49
 
50
- today = Date.new(2012, 10, 20)
51
- assert_equal(20000, @d02.priority(today))
50
+ today = Date.new(2012, 10, 20)
51
+ assert_equal(20000, @d02.priority(today))
52
52
 
53
53
 
54
- today = Date.new(2012, 10, 15)
55
- assert_equal(20000, @d03.priority(today))
56
- end
54
+ today = Date.new(2012, 10, 15)
55
+ assert_equal(20000, @d03.priority(today))
56
+ end
57
57
 
58
- def test_event_dates
59
- results = @d00.event_dates
60
- assert_equal(2 , results.size)
61
- assert_equal(Date.new(2012, 10, 5), results[0] )
62
- assert_equal(Date.new(2012, 10, 15), results[1] )
63
- assert_equal(Date , results[0].class )
64
- assert_equal(Date , results[1].class )
58
+ def test_event_dates
59
+ results = @d00.event_dates
60
+ assert_equal(2 , results.size)
61
+ assert_equal(Date.new(2012, 10, 5), results[0] )
62
+ assert_equal(Date.new(2012, 10, 15), results[1] )
63
+ assert_equal(Date , results[0].class )
64
+ assert_equal(Date , results[1].class )
65
65
 
66
- results = @d01.event_dates
67
- assert_equal(2 , results.size)
68
- assert_equal(Date.new(2012, 10, 5), results[0] )
69
- assert_equal(Date.new(2012, 10, 15), results[1] )
70
- assert_equal(Date , results[0].class )
71
- assert_equal(Date , results[1].class )
72
- end
66
+ results = @d01.event_dates
67
+ assert_equal(2 , results.size)
68
+ assert_equal(Date.new(2012, 10, 5), results[0] )
69
+ assert_equal(Date.new(2012, 10, 15), results[1] )
70
+ assert_equal(Date , results[0].class )
71
+ assert_equal(Date , results[1].class )
72
+ end
73
73
 
74
74
  end