sculd 0.0.3 → 0.1.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.
@@ -1,35 +1,43 @@
1
1
  #! /usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
- require "sculd/event.rb"
5
- require "sculd/plan.rb"
4
+ #require "sculd/event.rb"
5
+ #require "sculd/plan.rb"
6
6
 
7
7
  #
8
8
  #
9
9
  #
10
10
  class Sculd::Plan::Todo < Sculd::Plan
11
11
 
12
+ SYMBOL_CHAR = "+"
13
+ DEFAULT_OPTION = 7
14
+
12
15
  #
13
16
  def priority(today)
14
- @option = 1 if @option < 1
17
+ #@option = 1 if @option < 1
18
+ option = @option || DEFAULT_OPTION
15
19
  beginning = @datetime
16
- ending = @datetime + @option
20
+ ending = @datetime + option
17
21
  if today < beginning
18
22
  return 0
19
23
  elsif today <= ending
20
24
  rp = Sculd::Plan::REMINDER_PRIORITY
21
25
  dp = Sculd::Plan::DEADLINE_PRIORITY
22
- return (rp + (dp - rp) * (today - beginning)/(@option.to_f)).to_i
26
+ return (rp + (dp - rp) * (today - beginning)/(option.to_f)).to_i
23
27
  else
24
28
  return Sculd::Plan::DEADLINE_PRIORITY
25
29
  end
26
30
  end
27
31
 
28
- def events
32
+ def event_dates
33
+ #@option ||= DEFAULT_OPTION
34
+
29
35
  results = []
30
- results << Sculd::Event.new(@datetime, @description)
31
- results << Sculd::Event.new(@datetime + @option, @description)
32
- return 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
33
41
  end
34
42
  end
35
43
 
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
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
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'sculd'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,10 @@
1
+ [2012-09-15]@ schedule a
2
+ [2012-09-16]! deadline b
3
+ [2012-09-17]- reminder c
4
+ [2012-09-18]+ todo d
5
+ normal line
6
+
7
+ [2012-09-15 (Sat) 23:45]@ schedule a'
8
+ [2012-09-16 (Sun) 23:45]!30 deadline b'
9
+ [2012-09-17 (Mon) 23:45]- reminder c'
10
+ [2012-09-18 (Tue) 23:45]+10 todo d'
@@ -0,0 +1,5 @@
1
+ [2012-10-15]@ schedule a
2
+ [2012-10-16]! deadline b
3
+ [2012-10-17]- reminder c
4
+ [2012-10-18]+ todo d
5
+ normal line
@@ -0,0 +1,47 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "helper"
5
+
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')
10
+
11
+ date = DateTime.new(2012, 10, 15, 23, 45, 00)
12
+ @d01 = Sculd::Plan::Deadline.new(date, false, 10, 'deadlineA')
13
+ end
14
+
15
+ #context 'Date[2012-10-15], 10, [2012-10-15]!10 deadlineA' do
16
+
17
+ def test_priority
18
+ today = Date.new(2012, 10, 15)
19
+ assert_equal(20000, @d00.priority(today))
20
+
21
+ today = Date.new(2012, 10, 20)
22
+ assert_equal(20000, @d00.priority(today))
23
+
24
+ today = Date.new(2012, 10, 10)
25
+ assert_equal(15000, @d00.priority(today))
26
+
27
+ today = Date.new(2012, 10, 1)
28
+ assert_equal(0, @d00.priority(today))
29
+ end
30
+
31
+ def test_event_dates
32
+ results = @d00.event_dates
33
+ assert_equal(2 , results.size)
34
+ assert_equal(Date.new(2012, 10, 5), results[0] )
35
+ assert_equal(Date.new(2012, 10, 15), results[1] )
36
+ assert_equal(Date , results[0].class )
37
+ assert_equal(Date , results[1].class )
38
+
39
+ results = @d01.event_dates
40
+ assert_equal(2 , results.size)
41
+ assert_equal(Date.new(2012, 10, 5), results[0] )
42
+ assert_equal(Date.new(2012, 10, 15), results[1] )
43
+ assert_equal(Date , results[0].class )
44
+ assert_equal(Date , results[1].class )
45
+ end
46
+
47
+ end
@@ -0,0 +1,114 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "helper"
5
+ #require "test/unit"
6
+ #require "pkg/klass.rb"
7
+
8
+ class Sculd::Manager
9
+ public :load_file, :show_events, :days_events, :show_tasks
10
+ attr_accessor :plans
11
+ end
12
+
13
+ class TC_Manager < Test::Unit::TestCase
14
+ def setup
15
+ @s00 = Sculd::Manager.new("test/schedule/empty")
16
+ # @s01 = Sculd::Manager.new("test/schedule/normal")
17
+ end
18
+
19
+ # def test_load_file
20
+ # #context "correct data" do #it "should overwrite data" do
21
+ # @s00.load_file("test/schedule/normal/a.dat")
22
+ # assert_equal(8, @s00.plans.size)
23
+ # plans = @s00.plans
24
+ # assert(plans.shift.is_a? Sculd::Plan)
25
+ # assert(plans.shift.is_a? Sculd::Plan)
26
+ # assert(plans.shift.is_a? Sculd::Plan)
27
+ # assert(plans.shift.is_a? Sculd::Plan)
28
+ # assert(plans.shift.is_a? Sculd::Plan)
29
+ # assert(plans.shift.is_a? Sculd::Plan)
30
+ # assert(plans.shift.is_a? Sculd::Plan)
31
+ # assert(plans.shift.is_a? Sculd::Plan)
32
+ # end
33
+
34
+ def test_load_file_empty
35
+ @s00.load_file("test/schedule/empty/empty.dat")
36
+ assert_equal(0, @s00.plans.size)
37
+
38
+ #context "data containing error" do it "should interrupt with error line." do
39
+ io = StringIO.new
40
+ assert_raise(Sculd::Manager::LoadError){ @s00.load_file("test/schedule/error/error.dat", io)}
41
+ end
42
+
43
+ # def test_days_events
44
+ # #it 'should return hash dates as keys and events as values.' do
45
+ # #pp @s01
46
+ # results = @s01.days_events
47
+ # keys = results.keys
48
+ # #pp results
49
+ #
50
+ # ## normal/a.dat
51
+ # assert_equal(Date.new(2012, 9, 15), keys.shift)
52
+ # assert_equal(Date.new(2012, 9, 9), keys.shift)
53
+ # assert_equal(Date.new(2012, 9, 16), keys.shift)
54
+ # assert_equal(Date.new(2012, 9, 17), keys.shift)
55
+ # assert_equal(Date.new(2012, 9, 18), keys.shift)
56
+ # assert_equal(Date.new(2012, 9, 25), keys.shift)
57
+ # assert_equal(Date.new(2012, 8, 17), keys.shift)
58
+ # assert_equal(Date.new(2012, 9, 28), keys.shift)
59
+ # ## normal/b.dat
60
+ # assert_equal(Date.new(2012,10, 15), keys.shift)
61
+ # assert_equal(Date.new(2012,10, 9), keys.shift)
62
+ # assert_equal(Date.new(2012,10, 16), keys.shift)
63
+ # assert_equal(Date.new(2012,10, 17), keys.shift)
64
+ # assert_equal(Date.new(2012,10, 18), keys.shift)
65
+ # assert_equal(Date.new(2012,10, 25), keys.shift)
66
+ # assert_equal(nil , keys.shift)
67
+ #
68
+ # assert(results[Date.new(2012, 9, 15)].is_a? Array)
69
+ # assert(results[Date.new(2012, 9, 15)][0].is_a? Sculd::Plan)
70
+ # end
71
+ #
72
+ # def test_show_events
73
+ # #it 'should return itemized days and events' do
74
+ # #pp @s01
75
+ # io = StringIO.new
76
+ # today = Date.new(2012, 9, 15)
77
+ # @s01.show_events(2, today, io)
78
+ # io.rewind
79
+ # results = io.readlines
80
+ # #pp results
81
+ # #assert_equal(9, results.size)
82
+ # assert_equal("Events:\n" , results.shift)
83
+ # assert_equal("  2012-09-15 Sat \n",
84
+ # results.shift)
85
+ # assert_equal(" @ schedule a\n" , results.shift)
86
+ # assert_equal(" [23:45]@ schedule a'\n" , results.shift)
87
+ # assert_equal("\n" , results.shift)
88
+ # assert_equal("  2012-09-16 Sun \n",
89
+ # results.shift)
90
+ # assert_equal(" ! deadline b\n" , results.shift)
91
+ # assert_equal(" [23:45]!30 deadline b'\n" , results.shift)
92
+ # assert_equal("\n" , results.shift)
93
+ # assert_equal(nil , results.shift)
94
+ # end
95
+ #
96
+ # def test_show_tasks
97
+ # #it 'should return sorted tasks' do
98
+ # io = StringIO.new
99
+ # today = Date.new(2012, 9,20)
100
+ # @s01.show_tasks(6, today, io)
101
+ # io.rewind
102
+ # results = io.readlines
103
+ # #pp results
104
+ # #assert_equal(7, results.size)
105
+ # assert_equal("Tasks:\n" , results.shift)
106
+ # assert_equal(" [2012-09-16]!30 deadline b'\n", results.shift)
107
+ # assert_equal(" [2012-09-16]! deadline b\n" , results.shift)
108
+ # assert_equal(" [2012-09-18]+ todo d\n" , results.shift)
109
+ # assert_equal(" [2012-09-18]+10 todo d'\n", results.shift)
110
+ # assert_equal(" [2012-09-17]- reminder c'\n", results.shift)
111
+ # assert_equal(" [2012-09-17]- reminder c\n" , results.shift)
112
+ # assert_equal(nil , results.shift)
113
+ # end
114
+ end
@@ -0,0 +1,97 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "helper"
5
+ #require "test/unit"
6
+ #require "pkg/klass.rb"
7
+
8
+ class TC_Plan < Test::Unit::TestCase
9
+ def test_parse
10
+ ## correct string
11
+ result = Sculd::Plan.parse('[2012-10-23]! deadlineA')
12
+ date = DateTime.new(2012, 10, 23, 0, 0, 0)
13
+ assert_equal(date , result[:datetime])
14
+ assert_equal("!" , result[:type])
15
+ assert_equal(nil , result[:option])
16
+ assert_equal("deadlineA", result[:description])
17
+ assert_equal(false , result[:flag_time])
18
+
19
+ result = Sculd::Plan.parse('[2012-10-23]!30 deadlineA')
20
+ date = DateTime.new(2012, 10, 23, 0, 0, 0)
21
+ assert_equal(date , result[:datetime])
22
+ assert_equal("!" , result[:type])
23
+ assert_equal(30 , result[:option])
24
+ assert_equal("deadlineA", result[:description])
25
+ assert_equal(false , result[:flag_time])
26
+
27
+ result = Sculd::Plan.parse('[2012-10-23 01:02:03]@ scheduleA')
28
+ date = DateTime.new(2012, 10, 23, 1, 2, 3)
29
+ assert_equal(date , result[:datetime])
30
+ assert_equal("@" , result[:type])
31
+ assert_equal(nil , result[:option])
32
+ assert_equal("scheduleA", result[:description])
33
+ assert_equal(true , result[:flag_time])
34
+
35
+ result = Sculd::Plan.parse('[2012-11-01 01:02:03(Thu)]@ scheduleA')
36
+ date = DateTime.new(2012, 11, 1, 1, 2, 3)
37
+ assert_equal(date , result[:datetime])
38
+ assert_equal("@" , result[:type])
39
+ assert_equal(nil , result[:option])
40
+ assert_equal("scheduleA", result[:description])
41
+ assert_equal(true , result[:flag_time])
42
+
43
+ result = Sculd::Plan.parse('[2012-11-01 01:02:03(th)]@ scheduleA')
44
+ date = DateTime.new(2012, 11, 01, 1, 2, 3)
45
+ assert_equal(date , result[:datetime])
46
+ assert_equal("@" , result[:type])
47
+ assert_equal(nil , result[:option])
48
+ assert_equal("scheduleA", result[:description])
49
+ assert_equal(true , result[:flag_time])
50
+
51
+ #context 'schedule with wrong weekday' do
52
+ io = StringIO.new
53
+ assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(Sun)]@ scheduleA', io)}
54
+
55
+ assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse( "[2012-11-01(Fri)]@ mismach weekday\n", io)}
56
+
57
+ assert_raise(Sculd::Plan::NotWeekdayError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(abc)]@ scheduleA', io)}
58
+
59
+ #Unable to interpret as date in [].
60
+ #assert_raise(Sculd::Plan::NotDateError ){ Sculd::Plan.parse('[abc]! deadlineA')}
61
+ assert_raise(ArgumentError){ Sculd::Plan.parse('[abc]! deadlineA')}
62
+
63
+ ##Illegal syntax
64
+ # '[abc]]! deadlineA' do
65
+ assert_raise(Sculd::Plan::NotNumberError){
66
+ Sculd::Plan.parse('[2012-01-01]]! deadlineA')
67
+ }
68
+ #date = DateTime.new(2012, 01, 01)
69
+ #assert_equal(date , result[:datetime])
70
+ #assert_equal("]" , result[:type])
71
+ #assert_equal("!" , result[:option])
72
+ #assert_equal("deadlineA", result[:description])
73
+
74
+ #context ' [2012-10-23]! deadlineA with space at head' do
75
+ #it 'should return Date, !, deadlineA' do
76
+ result = Sculd::Plan.parse(' [2012-10-23]! deadlineA with space at head')
77
+ date = DateTime.new(2012, 10, 23)
78
+ assert_equal(date , result[:datetime])
79
+ assert_equal("!" , result[:type])
80
+ assert_equal(nil , result[:option])
81
+ assert_equal("deadlineA with space at head", result[:description])
82
+ assert_equal(false , result[:flag_time])
83
+
84
+ #context '[2012-10-23]!10 deadline with option value' do
85
+ #it 'should return Date, !, deadlineA' do
86
+ result = Sculd::Plan.parse( '[2012-10-23]!10 deadline with option value')
87
+ date = DateTime.new(2012, 10, 23)
88
+ assert_equal(date , result[:datetime])
89
+ assert_equal("!" , result[:type])
90
+ assert_equal(10 , result[:option])
91
+ assert_equal("deadline with option value", result[:description])
92
+ assert_equal(false , result[:flag_time])
93
+
94
+
95
+
96
+ end
97
+ end
@@ -0,0 +1,38 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "helper"
5
+ #require "test/unit"
6
+ #require "pkg/klass.rb"
7
+
8
+ class TC_Klass < Test::Unit::TestCase
9
+ def setup
10
+ date = Date.new(2012, 10, 23)
11
+ @r00 = Sculd::Plan::Reminder.new(date, false, 10, 'reminderA')
12
+
13
+ date = DateTime.new(2012, 10, 23, 23, 45, 00)
14
+ @r01 = Sculd::Plan::Reminder.new(date, false, 10, 'reminderA')
15
+ end
16
+
17
+ def test_priority
18
+ #it 'return REMINDER_PRIORITY when the day is today .' do
19
+ date = Date.new(2012, 10, 23)
20
+ assert_equal(10000, @r00.priority(date))
21
+
22
+ #it 'return REMINDER_PRIORITY -1 when the day is yesterday .' do
23
+ date = Date.new(2012, 10, 24)
24
+ assert_equal(9999, @r00.priority(date))
25
+ end
26
+
27
+ def test_event_dates
28
+ #it 'return a Sculd::Event instance.' do
29
+ results = @r00.event_dates
30
+ assert_equal([Date.new(2012, 10, 23)], results)
31
+
32
+ results = @r01.event_dates
33
+ assert_equal(1 , results.size)
34
+ assert_equal(Date.new(2012, 10, 23), results[0] )
35
+ assert_equal(Date , results[0].class )
36
+ end
37
+ end
38
+
@@ -0,0 +1,30 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "helper"
5
+ #require "test/unit"
6
+ #require "pkg/klass.rb"
7
+
8
+ class TC_Schedule < Test::Unit::TestCase
9
+ def setup
10
+ date = Date.new(2012, 10, 15)
11
+ @s00 = Sculd::Plan::Schedule.new(date, false, 0, "scheduleA")
12
+
13
+ date = DateTime.new(2012, 10, 15, 23, 45, 0)
14
+ @s01 = Sculd::Plan::Schedule.new(date, false, 0, "scheduleA")
15
+ end
16
+
17
+ def test_priority
18
+ #it 'should return 0' do
19
+ assert_equal(0, @s00.priority)
20
+ end
21
+
22
+ def test_event_dates
23
+ #it 'should return Array of 1 item' do
24
+ results = @s00.event_dates
25
+ assert_equal([Date.new(2012, 10, 15)], results)
26
+
27
+ results = @s01.event_dates
28
+ assert_equal([Date.new(2012, 10, 15)], results)
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "helper"
5
+ #require "test/unit"
6
+ #require "pkg/klass.rb"
7
+
8
+ class TC_Todo < Test::Unit::TestCase
9
+ def setup
10
+ today = Date.new(2012, 10, 15)
11
+ @t00 = Sculd::Plan::Todo.new(today, false, 10, 'todoA')
12
+
13
+ today = DateTime.new(2012, 10, 15, 23, 45, 00)
14
+ @t01 = Sculd::Plan::Todo.new(today, false, 10, 'todoA')
15
+ end
16
+
17
+ def test_priority
18
+ #it 'return 0 before the period.' do
19
+ today = Date.new(2012, 10, 1)
20
+ assert_equal(0, @t00.priority(today))
21
+
22
+ #it 'return REMINDER_PRIORITY when the day is today.' do
23
+ today = Date.new(2012, 10, 15)
24
+ assert_equal(10000, @t00.priority(today))
25
+
26
+ #it 'return values between REMINDER_PRIORITY and DEADLINE_PRIORITY during the period.' do
27
+ today = Date.new(2012, 10, 20)
28
+ assert_equal(15000, @t00.priority(today))
29
+
30
+ #it 'return DEADLINE_PRIORITY when the day is past.' do
31
+ today = Date.new(2012, 10, 30)
32
+ assert_equal(20000, @t00.priority(today))
33
+ end
34
+
35
+ def test_event_dates
36
+ results = @t00.event_dates
37
+ assert_equal(2, results.size)
38
+ assert_equal(Date.new(2012, 10, 15), results[0])
39
+ assert_equal(Date.new(2012, 10, 25), results[1])
40
+
41
+
42
+ results = @t01.event_dates
43
+ assert_equal(2 , results.size)
44
+ assert_equal(Date.new(2012, 10, 15), results[0] )
45
+ assert_equal(Date.new(2012, 10, 25), results[1] )
46
+ assert_equal(Date , results[0].class )
47
+ assert_equal(Date , results[1].class )
48
+ end
49
+ end
50
+