koyomi 0.0.5 → 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9fae146cc8b22c7813777006c1c558509aa3761
4
+ data.tar.gz: 1294496c32deba891b31dbe5334e44fb2db1db2f
5
+ SHA512:
6
+ metadata.gz: 31eb8318ced1c68908e02837c9ca867ec673f8daa785f60b287f97d963edcfa285866c05c5f128c6456a50be968c6bd91387fb16609b3e5e67509c0cb010eb86
7
+ data.tar.gz: 3672260d0178567dd8b173e6dffc005fb769edd8d567567dafe676e8b4c445a771d79bcd91ddd2796ad3a005978123e018ef6081418943b60a97bef60305c45c
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -16,5 +15,8 @@ test/tmp
16
15
  test/version_tmp
17
16
  tmp
18
17
  ._*
19
- .DSStore
18
+ .DS_Store
20
19
  .project
20
+ vendor/bundle
21
+ log
22
+ log/*.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## 0.1.0 (2015-11-15)
4
+
5
+ * use rspec
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ koyomi (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.0)
10
+ diff-lcs (1.2.5)
11
+ ffi (1.9.10)
12
+ formatador (0.2.5)
13
+ guard (2.13.0)
14
+ formatador (>= 0.2.4)
15
+ listen (>= 2.7, <= 4.0)
16
+ lumberjack (~> 1.0)
17
+ nenv (~> 0.1)
18
+ notiffany (~> 0.0)
19
+ pry (>= 0.9.12)
20
+ shellany (~> 0.0)
21
+ thor (>= 0.18.1)
22
+ guard-compat (1.2.1)
23
+ guard-rspec (4.6.4)
24
+ guard (~> 2.1)
25
+ guard-compat (~> 1.1)
26
+ rspec (>= 2.99.0, < 4.0)
27
+ listen (3.0.4)
28
+ rb-fsevent (>= 0.9.3)
29
+ rb-inotify (>= 0.9)
30
+ lumberjack (1.0.9)
31
+ method_source (0.8.2)
32
+ nenv (0.2.0)
33
+ notiffany (0.0.8)
34
+ nenv (~> 0.1)
35
+ shellany (~> 0.0)
36
+ pry (0.10.3)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.8.1)
39
+ slop (~> 3.4)
40
+ rb-fsevent (0.9.6)
41
+ rb-inotify (0.9.5)
42
+ ffi (>= 0.5.0)
43
+ rspec (3.4.0)
44
+ rspec-core (~> 3.4.0)
45
+ rspec-expectations (~> 3.4.0)
46
+ rspec-mocks (~> 3.4.0)
47
+ rspec-core (3.4.0)
48
+ rspec-support (~> 3.4.0)
49
+ rspec-expectations (3.4.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.4.0)
52
+ rspec-its (1.2.0)
53
+ rspec-core (>= 3.0.0)
54
+ rspec-expectations (>= 3.0.0)
55
+ rspec-mocks (3.4.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.4.0)
58
+ rspec-support (3.4.0)
59
+ shellany (0.0.1)
60
+ slop (3.6.0)
61
+ thor (0.19.1)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ guard-rspec
68
+ koyomi!
69
+ rspec
70
+ rspec-its
71
+
72
+ BUNDLED WITH
73
+ 1.10.6
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ # rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ # dsl.watch_spec_files_for(rails.app_files)
46
+ # dsl.watch_spec_files_for(rails.views)
47
+
48
+ # watch(rails.controllers) do |m|
49
+ # [
50
+ # rspec.spec.("routing/#{m[1]}_routing"),
51
+ # rspec.spec.("controllers/#{m[1]}_controller"),
52
+ # rspec.spec.("acceptance/#{m[1]}")
53
+ # ]
54
+ # end
55
+
56
+ # Rails config changes
57
+ # watch(rails.spec_helper) { rspec.spec_dir }
58
+ # watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ # watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ # watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
63
+ # watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ # watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ # watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ # Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ # end
70
+ end
data/README.md CHANGED
@@ -25,18 +25,18 @@ Handling calendar by this gem.
25
25
  require "koyomi"
26
26
  cal = Koyomi::Calendar.new(2012, 12, :mon)
27
27
  cal.first.to_s # => "2012-11-26"
28
-
28
+
29
29
  cal.first.week_end? # => false
30
30
  cal.first.week_end?(:tue) # => true
31
-
31
+
32
32
  month = cal.the_month
33
33
  month.first.to_s # => "2012-12-01"
34
-
34
+
35
35
  week = Koyomi::Week.new(month.first, :tue)
36
36
  week.first.to_s # => "2012-11-27"
37
-
37
+
38
38
  # weeks and week days.
39
-
39
+
40
40
  # nth week day.
41
41
  #
42
42
  # Version 0.0.5 or later, NOT compatible version 0.0.4.x.
@@ -45,14 +45,14 @@ Handling calendar by this gem.
45
45
  # (japanese)
46
46
  # バージョン 0.0.5 以上では、バージョン 0.0.4.x と互換性がありません。
47
47
  # 以前のバージョンと同様の結果を得るためには、 Koyomi::Month#nth_wday メソッドを利用して下さい。
48
- #
48
+ #
49
49
  cal.nth_wday(1, :sat).to_s
50
50
  # => "2012-12-01"
51
51
  cal.nth_wday(1, :tue).to_s
52
52
  # => "2012-11-27"
53
53
  cal.the_month.nth_wday(1, :tue).to_s
54
54
  # => "2012-12-04"
55
-
55
+
56
56
  # cycle: every monday.
57
57
  # (japanese) 周期:毎週月曜
58
58
  cal.cycles(:every, :mon).collect { |d| d.to_s }
@@ -64,18 +64,18 @@ Handling calendar by this gem.
64
64
  # (japanese)
65
65
  # バージョン 0.0.5 以上では、バージョン 0.0.4.x と互換性がありません。
66
66
  # 以前のバージョンと同様の結果を得るためには、 Koyomi::Month#cycles メソッドを利用して下さい。
67
- #
67
+ #
68
68
  cal.the_month.cycles(:every, :mon).collect { |d| d.to_s }
69
69
  # => ["2012-12-03", "2012-12-10", "2012-12-17", "2012-12-24", "2012-12-31"]
70
-
70
+
71
71
  # cycle: 1st, 3rd week's tuesday or friday.
72
72
  # (japanese) 周期:第1、第3の火曜と金曜
73
- #
73
+ #
74
74
  cal.cycles([1, 3], [:tue, :fri]).collect { |d| d.to_s }
75
75
  # => ["2012-11-27", "2012-11-30", "2012-12-11", "2012-12-14"]
76
76
  cal.the_month.cycles([1, 3], [:tue, :fri]).collect { |d| d.to_s }
77
77
  # => ["2012-12-04", "2012-12-07", "2012-12-18", "2012-12-21"]
78
-
78
+
79
79
 
80
80
  ## Contributing
81
81
 
data/Rakefile CHANGED
@@ -1,21 +1,7 @@
1
1
  # encoding: utf-8
2
- require "bundler/gem_tasks"
3
- require "rake/testtask"
4
-
5
2
  $: << File.expand_path("../lib", __FILE__)
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
6
5
 
7
- task :default do
8
- sh "rake -T"
9
- end
10
-
11
- Rake::TestTask.new do |t|
12
- t.libs << "test"
13
- t.test_files = FileList["test/**/test_*.rb"]
14
- end
15
-
16
- namespace :test do
17
- Rake::TestTask.new(:units) do |t|
18
- t.libs << "test"
19
- t.test_files = FileList["test/units/**/test_*.rb"]
20
- end
21
- end
6
+ RSpec::Core::RakeTask.new("spec")
7
+ task :default => :spec
@@ -17,9 +17,11 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
-
20
+
21
21
  #--------------------#
22
22
  # additionals
23
- gem.add_development_dependency "shoulda"
24
-
23
+ gem.add_development_dependency "rspec"
24
+ gem.add_development_dependency "rspec-its"
25
+ gem.add_development_dependency "guard-rspec"
26
+
25
27
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Koyomi
4
- VERSION = "0.0.5"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -0,0 +1,2 @@
1
+ require "spec_helper"
2
+ require "koyomi"
@@ -0,0 +1,169 @@
1
+ require "koyomi_helper"
2
+
3
+ describe Koyomi::Calendar do
4
+ let(:calendar) { described_class.new() }
5
+
6
+ describe ".of" do
7
+ subject { described_class.of(date) }
8
+ let(:date) { today }
9
+ let!(:today) { Date.today }
10
+
11
+ it { is_expected.to be_kind_of(described_class) }
12
+ its(:month) { is_expected.to eq date.month }
13
+ end
14
+
15
+ describe "#koyomi_month" do
16
+ subject { calendar.koyomi_month }
17
+
18
+ example("get month") { is_expected.to be_kind_of(Koyomi::Month) }
19
+
20
+ example("has alias 'the_month'") do
21
+ expect do
22
+ calendar.the_month
23
+ end.not_to raise_exception
24
+ end
25
+ end
26
+
27
+ describe "#month" do
28
+ subject { calendar.month }
29
+
30
+ it { is_expected.to be_kind_of(Integer) }
31
+ end
32
+
33
+ describe "#week_start" do
34
+ subject { calendar.week_start }
35
+
36
+ it { is_expected.to be_kind_of(Numeric) }
37
+ end
38
+
39
+ describe "#week_start=" do
40
+ Koyomi::Week::WDAYS.each do |wday|
41
+ context "week starts with #{wday}" do
42
+ before { calendar.week_start = wday }
43
+ describe "#first" do
44
+ it { expect(calendar.first.wday).to eq Koyomi::Week::WDAYS.index(wday) }
45
+ end
46
+
47
+ describe "#last" do
48
+ it { expect(calendar.last.wday).to eq ((Koyomi::Week::WDAYS.index(wday) + 6) % 7)}
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#weeks" do
55
+ subject { calendar.weeks }
56
+
57
+ describe "size" do
58
+ subject { calendar.weeks.size }
59
+ let(:calendar) { described_class.new(*test_case) }
60
+ let(:test_case) { nil }
61
+
62
+ context "has 5 weeks" do
63
+ # 2015-11 ~ 2015-12 start with sunday
64
+ #
65
+ # 1 2 3 4 5 6 7
66
+ # 8 9 10 11 12 13 14
67
+ # 15 16 17 18 19 20 21
68
+ # 22 23 24 25 26 27 28
69
+ # 29 30 1 2 3 4 5
70
+ #
71
+ # #=> 5 weeks
72
+ let(:test_case) { [2015, 11, :sun] }
73
+ it { is_expected.to eq 5 }
74
+ end # context "has 5 weeks"
75
+
76
+ context "has 6 weeks" do
77
+ # 2015-10 ~ 2015-12 start with monday
78
+ #
79
+ # 26 27 28 29 30 31 1
80
+ # 2 3 4 5 6 7 8
81
+ # 9 10 11 12 13 14 15
82
+ # 16 17 18 19 20 21 22
83
+ # 23 24 25 26 27 28 29
84
+ # 30 1 2 3 4 5 6
85
+ #
86
+ # #=> 6 weeks
87
+ let(:test_case) { [2015, 11, :mon] }
88
+ it { is_expected.to eq 6 }
89
+ end # context "has 6 weeks"
90
+ end # describe size
91
+ end
92
+
93
+ describe "#nth_wday" do
94
+ let(:calendar) { described_class.new(2015, 11, :sun) }
95
+ # 2015-11 ~ 2015-12 start with sunday
96
+ #
97
+ # 1 2 3 4 5 6 7
98
+ # 8 9 10 11 12 13 14
99
+ # 15 16 17 18 19 20 21
100
+ # 22 23 24 25 26 27 28
101
+ # 29 30 1 2 3 4 5
102
+
103
+ context "first saturday" do
104
+ subject { calendar.nth_wday(1, :sat) }
105
+ it { is_expected.to eq Date.new(2015, 11, 7) }
106
+ end
107
+
108
+ context "5th tuesday" do
109
+ subject { calendar.nth_wday(5, :tue) }
110
+ it { is_expected.to eq Date.new(2015, 12, 1) }
111
+ end
112
+
113
+ context "range over" do
114
+ subject { calendar.nth_wday(6, :mon) }
115
+
116
+ xit "[TODO] raise Koyomi::WrongRangeError" do
117
+ expect { subject }.to raise_error(NoMethodError)
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "#wdays" do
123
+ Koyomi::Week::WDAYS.each do |wday|
124
+ describe "size" do
125
+ subject { calendar.wdays(wday).size }
126
+
127
+ context "has 5 weeks" do
128
+ let(:calendar) { described_class.new(2015, 11, :sun) }
129
+ it { is_expected.to eq 5 }
130
+ end
131
+
132
+ context "has 6 weeks" do
133
+ let(:calendar) { described_class.new(2015, 11, :mon) }
134
+ it { is_expected.to eq 6 }
135
+ end
136
+ end # describe "size"
137
+ end
138
+ end
139
+
140
+ describe "#cycles" do
141
+ subject { calendar.cycles(*test_case) }
142
+
143
+ context "first and third tuesday and friday" do
144
+ let(:test_case) { [[1, 3], [:tue, :fri]] }
145
+ it { expect(subject.size).to eq 4 }
146
+
147
+ it "days has requested week day" do
148
+ subject.each do |date|
149
+ expect([:tue, :fri]).to include(date.wday_name)
150
+ end
151
+ end
152
+ end # context "first and third tuesday and friday"
153
+
154
+ context "every monday and friday" do
155
+ let(:test_case) { [:every, [:mon, :fri]] }
156
+ let(:calendar) { described_class.new(2015, 12, :mon) }
157
+ # 2015-11 ~ 2016-01 start with monday
158
+ #
159
+ # 30 1 2 3 4 5 6
160
+ # 7 8 9 10 11 12 13
161
+ # 14 15 16 17 18 19 20
162
+ # 21 22 23 24 25 26 27
163
+ # 28 29 30 31 2 3 4
164
+
165
+ it { expect(subject.size).to eq 10 }
166
+ it { expect(subject.first.month).not_to eq calendar.month}
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,64 @@
1
+ require "koyomi_helper"
2
+
3
+ describe Date do
4
+ let(:date) { described_class.new(2015, 12, 1) }
5
+
6
+ describe "#week_start?" do
7
+ context "week starts with the date" do
8
+ it { expect(date.week_start?(:tue)).to be_truthy }
9
+ end
10
+
11
+ context "week not starts with the date" do
12
+ it { expect(date.week_start?(:sun)).to be_falsy }
13
+ it { expect(date.week_start?(:mon)).to be_falsy }
14
+ # it { expect(date.week_start?(:tue)).to be_truthy }
15
+ it { expect(date.week_start?(:wed)).to be_falsy }
16
+ it { expect(date.week_start?(:thu)).to be_falsy }
17
+ it { expect(date.week_start?(:fri)).to be_falsy }
18
+ it { expect(date.week_start?(:sat)).to be_falsy }
19
+ end
20
+ end
21
+
22
+ describe "#week_end?" do
23
+ context "week ends with the date" do
24
+ it { expect(date.week_end?(:wed)).to be_truthy }
25
+ end
26
+
27
+ context "week not ends with the date" do
28
+ it { expect(date.week_end?(:sun)).to be_falsy }
29
+ it { expect(date.week_end?(:mon)).to be_falsy }
30
+ it { expect(date.week_end?(:tue)).to be_falsy }
31
+ # it { expect(date.week_end?(:wed)).to be_truthy }
32
+ it { expect(date.week_end?(:thu)).to be_falsy }
33
+ it { expect(date.week_end?(:fri)).to be_falsy }
34
+ it { expect(date.week_end?(:sat)).to be_falsy }
35
+ end
36
+ end
37
+
38
+ describe "#nth_month_week" do
39
+ subject { date.nth_month_week }
40
+ it { is_expected.to eq 1 }
41
+
42
+ context "2015-12-31" do
43
+ let(:date) { Date.new(2015, 12, 31) }
44
+ it { is_expected.to eq 5 }
45
+ end
46
+ end
47
+
48
+ describe "#nth_wday" do
49
+ subject { date.nth_wday }
50
+ it { is_expected.to eq [1, :tue] }
51
+ end
52
+
53
+ describe "#month_info" do
54
+ subject { date.month_info }
55
+
56
+ # nth
57
+ it { expect(subject).to have_key(:nth) }
58
+ its([:nth]) { is_expected.to eq 1 }
59
+
60
+ # wday
61
+ it { expect(subject).to have_key(:wday) }
62
+ its([:wday]) { is_expected.to eq :tue }
63
+ end
64
+ end
@@ -0,0 +1,108 @@
1
+ require "koyomi_helper"
2
+
3
+ describe Koyomi::Month do
4
+ let(:month) { described_class.new(today.month, today.year) }
5
+ let!(:today) { Date.today }
6
+
7
+ describe "#range" do
8
+ subject { month.range }
9
+
10
+ it { is_expected.to be_kind_of(Range) }
11
+ end
12
+
13
+ describe "#month" do
14
+ subject { month.month }
15
+
16
+ it { is_expected.to eq today.month }
17
+ end
18
+
19
+ describe "#next" do
20
+ subject { month.next }
21
+
22
+ it { is_expected.to be_kind_of(described_class) }
23
+ it { expect(subject.month).to eq ((month.first + 32).month) }
24
+ end
25
+
26
+ describe "#prev" do
27
+ subject { month.prev }
28
+
29
+ it { is_expected.to be_kind_of(described_class) }
30
+ it { expect(subject.month).to eq ((month.first - 1).month) }
31
+ end
32
+
33
+ describe "#nth_wday" do
34
+ subject { month.nth_wday(*test_case) }
35
+ let(:month) { described_class.new(12, 2015) }
36
+ # 2015-12
37
+ # 1 2 3 4 5 6
38
+ # 7 8 9 10 11 12 13
39
+ # 14 15 16 17 18 19 20
40
+ # 21 22 23 24 25 26 27
41
+ # 28 29 30 31
42
+
43
+ context "first saturday" do
44
+ let(:test_case) { [1, :sat] }
45
+ it { is_expected.to eq Date.new(2015, 12, 5) }
46
+ end
47
+
48
+ context "last saturday" do
49
+ let(:test_case) { [:last, :sat] }
50
+ xit { is_expected.to eq Date.new(2015, 12, 26) }
51
+ end
52
+
53
+ context "5th friday" do
54
+ let(:test_case) { [5, :fri] }
55
+ xit("[TODO] raise Koyomi::WrongRangeError") {
56
+ is_expected.to raise_error(Koyomi::WrongRangeError)
57
+ }
58
+ end
59
+ end
60
+
61
+ describe "#wdays" do
62
+ subject { month.wdays(test_case) }
63
+ let(:month) { described_class.new(12, 2015) }
64
+ # 2015-12
65
+ # 1 2 3 4 5 6
66
+ # 7 8 9 10 11 12 13
67
+ # 14 15 16 17 18 19 20
68
+ # 21 22 23 24 25 26 27
69
+ # 28 29 30 31
70
+
71
+ context "monday" do
72
+ let(:test_case) { :mon }
73
+ it { expect(subject.size).to eq 4 }
74
+ end
75
+
76
+ context "tuesday" do
77
+ let(:test_case) { :tue }
78
+ it { expect(subject.size).to eq 5 }
79
+ end
80
+ end
81
+
82
+ describe "#cycles" do
83
+ subject { month.cycles(*test_case) }
84
+ let(:month) { described_class.new(12, 2015) }
85
+ # 2015-12
86
+ # 1 2 3 4 5 6
87
+ # 7 8 9 10 11 12 13
88
+ # 14 15 16 17 18 19 20
89
+ # 21 22 23 24 25 26 27
90
+ # 28 29 30 31
91
+
92
+ context "first and third monday, friday" do
93
+ # 4, 7, 18, 21
94
+ let(:test_case) { [[1, 3], [:mon, :fri]] }
95
+ its(:size) { is_expected.to eq 4 }
96
+ its(:first) { is_expected.to eq Date.new(2015, 12, 4) }
97
+ its(:last) { is_expected.to eq Date.new(2015, 12, 21) }
98
+ end
99
+
100
+ context "every monday, thursday" do
101
+ # 3, 7, 10, 14, 17, 21, 24, 28, 31
102
+ let(:test_case) { [:every, [:mon, :thu]] }
103
+ its(:size) { is_expected.to eq 9 }
104
+ its(:first) { is_expected.to eq Date.new(2015, 12, 3) }
105
+ its(:last) { is_expected.to eq Date.new(2015, 12, 31) }
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe Koyomi::VERSION do
4
+ example("has version") { expect(Koyomi::VERSION).not_to be_empty }
5
+ end
@@ -0,0 +1,53 @@
1
+ require "koyomi_helper"
2
+
3
+ describe Koyomi::Week do
4
+ let(:week) { described_class.new(date, week_start) }
5
+ let!(:today) { Date.today }
6
+
7
+ describe ".windex" do
8
+ it { expect(described_class.windex(:sun)). to eq 0 }
9
+ it { expect(described_class.windex(:mon)). to eq 1 }
10
+ it { expect(described_class.windex(:tue)). to eq 2 }
11
+ it { expect(described_class.windex(:wed)). to eq 3 }
12
+ it { expect(described_class.windex(:thu)). to eq 4 }
13
+ it { expect(described_class.windex(:fri)). to eq 5 }
14
+ it { expect(described_class.windex(:sat)). to eq 6 }
15
+ end
16
+
17
+ context "include 2015-12-01" do
18
+ let(:date) { Date.new(2015, 12, 1) }
19
+
20
+ context "start with monday(2015-11-30 ~ 2015-12-06)" do
21
+ let(:week_start) { :mon }
22
+
23
+ describe "#range" do
24
+ subject { week.range }
25
+ its(:count) { is_expected.to eq 7 }
26
+ its(:first) { is_expected.to eq Date.new(2015, 11, 30) }
27
+ its(:last) { is_expected.to eq Date.new(2015, 12, 6) }
28
+ end
29
+
30
+ describe "wday name method" do
31
+ it { expect(week.sun).to eq Date.new(2015, 12, 6) }
32
+ it { expect(week.mon).to eq Date.new(2015, 11, 30) }
33
+ it { expect(week.tue).to eq Date.new(2015, 12, 1) }
34
+ it { expect(week.wed).to eq Date.new(2015, 12, 2) }
35
+ it { expect(week.thu).to eq Date.new(2015, 12, 3) }
36
+ it { expect(week.fri).to eq Date.new(2015, 12, 4) }
37
+ it { expect(week.sat).to eq Date.new(2015, 12, 5) }
38
+ end
39
+ end # context "start with monday(2015-11-30 ~ 2015-12-06)"
40
+
41
+ context "start with sunday(2015-11-29 ~ 2015-12-05)" do
42
+ let(:week_start) { :sun }
43
+
44
+ describe "#range" do
45
+ subject { week.range }
46
+ its(:count) { is_expected.to eq 7 }
47
+ its(:first) { is_expected.to eq Date.new(2015, 11, 29) }
48
+ its(:last) { is_expected.to eq Date.new(2015, 12, 5) }
49
+ end
50
+ end # context "start with monday(2015-11-29 ~ 2015-12-05)"
51
+
52
+ end # context "include 2015-12-01"
53
+ end
@@ -0,0 +1,98 @@
1
+ require "rspec/its"
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Allows RSpec to persist some state between runs in order to support
56
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
57
+ # you configure your source control system to ignore this file.
58
+ config.example_status_persistence_file_path = "spec/examples.txt"
59
+
60
+ # Limits the available syntax to the non-monkey patched syntax that is
61
+ # recommended. For more details, see:
62
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = 'doc'
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
metadata CHANGED
@@ -1,30 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koyomi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - sekizo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: shoulda
14
+ name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-its
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
28
53
  - !ruby/object:Gem::Version
29
54
  version: '0'
30
55
  description: Extends Date class to handling with calendar.
@@ -34,8 +59,12 @@ executables: []
34
59
  extensions: []
35
60
  extra_rdoc_files: []
36
61
  files:
37
- - .gitignore
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - CHANGELOG.md
38
65
  - Gemfile
66
+ - Gemfile.lock
67
+ - Guardfile
39
68
  - LICENSE.txt
40
69
  - README.md
41
70
  - Rakefile
@@ -51,40 +80,42 @@ files:
51
80
  - lib/koyomi/period.rb
52
81
  - lib/koyomi/version.rb
53
82
  - lib/koyomi/week.rb
54
- - test/test_helper.rb
55
- - test/units/test_calendar.rb
56
- - test/units/test_date.rb
57
- - test/units/test_month.rb
58
- - test/units/test_week.rb
83
+ - spec/koyomi_helper.rb
84
+ - spec/lib/koyomi/calendar_spec.rb
85
+ - spec/lib/koyomi/date_spec.rb
86
+ - spec/lib/koyomi/month_spec.rb
87
+ - spec/lib/koyomi/version_spec.rb
88
+ - spec/lib/koyomi/week_spec.rb
89
+ - spec/spec_helper.rb
59
90
  homepage: ''
60
91
  licenses:
61
92
  - MIT
93
+ metadata: {}
62
94
  post_install_message:
63
95
  rdoc_options: []
64
96
  require_paths:
65
97
  - lib
66
98
  required_ruby_version: !ruby/object:Gem::Requirement
67
- none: false
68
99
  requirements:
69
- - - ! '>='
100
+ - - ">="
70
101
  - !ruby/object:Gem::Version
71
102
  version: '0'
72
103
  required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
104
  requirements:
75
- - - ! '>='
105
+ - - ">="
76
106
  - !ruby/object:Gem::Version
77
107
  version: '0'
78
108
  requirements: []
79
109
  rubyforge_project:
80
- rubygems_version: 1.8.24
110
+ rubygems_version: 2.4.8
81
111
  signing_key:
82
- specification_version: 3
112
+ specification_version: 4
83
113
  summary: Add some classes to handle year, month, period.
84
114
  test_files:
85
- - test/test_helper.rb
86
- - test/units/test_calendar.rb
87
- - test/units/test_date.rb
88
- - test/units/test_month.rb
89
- - test/units/test_week.rb
90
- has_rdoc:
115
+ - spec/koyomi_helper.rb
116
+ - spec/lib/koyomi/calendar_spec.rb
117
+ - spec/lib/koyomi/date_spec.rb
118
+ - spec/lib/koyomi/month_spec.rb
119
+ - spec/lib/koyomi/version_spec.rb
120
+ - spec/lib/koyomi/week_spec.rb
121
+ - spec/spec_helper.rb
@@ -1,6 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "shoulda"
4
- require File.expand_path("../../lib/koyomi", __FILE__)
5
-
6
- require "test/unit"
@@ -1,138 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "test_helper"
4
-
5
- class TestKoyomiCalendar < Test::Unit::TestCase
6
- context "Koyomi::Calendar" do
7
- setup do
8
- @calendar = Koyomi::Calendar.new()
9
- end # setup
10
-
11
- should "have koyomi month" do
12
- assert(@calendar.koyomi_month.is_a?(Koyomi::Month))
13
- assert(@calendar.the_month.is_a?(Koyomi::Month))
14
- end # should "have koyomi month"
15
-
16
- should "have week start" do
17
- assert(@calendar.week_start.is_a?(Numeric))
18
-
19
- assert_nothing_raised(Exception) do
20
- (0..6).each do |wd|
21
- @calendar.week_start = wd
22
- end
23
- end
24
-
25
- assert_raise(RuntimeError) do
26
- @calendar.week_start = 7
27
- end
28
- end # should "have week start"
29
-
30
- context "handle correct week" do
31
- setup do
32
- @cal = Koyomi::Calendar.new(2012, 12)
33
- end # setup
34
-
35
- should "starts sun." do
36
- @cal.week_start = :sun
37
- assert_equal(Date.new(2012, 11, 25), @cal.first, "wrong first.")
38
- assert_equal(Date.new(2013, 1, 5), @cal.last, "wrong last.")
39
- end
40
-
41
- should "starts mon." do
42
- @cal.week_start = :mon
43
- assert_equal(Date.new(2012, 11, 26), @cal.first, "wrong first.")
44
- assert_equal(Date.new(2013, 1, 6), @cal.last, "wrong last.")
45
- end
46
-
47
- should "starts tue." do
48
- @cal.week_start = :tue
49
- assert_equal(Date.new(2012, 11, 27), @cal.first, "wrong first.")
50
- assert_equal(Date.new(2012, 12, 31), @cal.last, "wrong last.")
51
- end
52
-
53
- should "starts wed." do
54
- @cal.week_start = :wed
55
- assert_equal(Date.new(2012, 11, 28), @cal.first, "wrong first.")
56
- assert_equal(Date.new(2013, 1, 1), @cal.last, "wrong last.")
57
- end
58
-
59
- should "starts thu." do
60
- @cal.week_start = :thu
61
- assert_equal(Date.new(2012, 11, 29), @cal.first, "wrong first.")
62
- assert_equal(Date.new(2013, 1, 2), @cal.last, "wrong last.")
63
- end
64
-
65
- should "starts fri." do
66
- @cal.week_start = :fri
67
- assert_equal(Date.new(2012, 11, 30), @cal.first, "wrong first.")
68
- assert_equal(Date.new(2013, 1, 3), @cal.last, "wrong last.")
69
- end
70
-
71
- should "starts sat." do
72
- @cal.week_start = :sat
73
- assert_equal(Date.new(2012, 12, 1), @cal.first, "wrong first.")
74
- assert_equal(Date.new(2013, 1, 4), @cal.last, "wrong last.")
75
- end
76
-
77
- end # context "handle correct week"
78
-
79
- context "week methods" do
80
-
81
- setup do
82
- @cal = Koyomi::Calendar.new(2012, 12, :mon)
83
- end
84
-
85
- should "have weeks" do
86
- assert_equal(6, @cal.weeks.size)
87
-
88
- cal = Koyomi::Calendar.new(2012, 12, :tue)
89
- assert_equal(5, cal.weeks.size)
90
- end # should "have weeks"
91
-
92
- should "respond to nth_wday" do
93
- assert_equal(Date.new(2012,12,1), @cal.nth_wday(1, :sat))
94
-
95
- # version 0.0.5 or later
96
- assert_equal(Date.new(2012,11,27), @cal.nth_wday(1, :tue))
97
- end # should "respond to nth_wday"
98
-
99
- should "respond to wdays" do
100
- # version 0.0.4.x
101
- #assert_equal(5, @cal.wdays(:sat).size)
102
- #assert_equal(4, @cal.wdays(:fri).size)
103
-
104
- # version 0.0.5 or later
105
- assert_equal(6, @cal.wdays(:sat).size)
106
- assert_equal(6, @cal.wdays(:fri).size)
107
- end # should "respond to wdays"
108
-
109
- should "respond to cycles" do
110
- dates = @cal.cycles([1, 3], [:tue, :fri])
111
- assert_equal(4, dates.size)
112
-
113
- dates.each do |date|
114
- assert((date.wday_name == :tue) || (date.wday_name == :fri))
115
- end
116
-
117
- # version 0.0.5 or later
118
- dates = @cal.cycles(:every, [:tue, :fri])
119
- assert_equal(12, dates.size)
120
-
121
- dates.each do |date|
122
- assert((date.wday_name == :tue) || (date.wday_name == :fri))
123
- end
124
-
125
- @cal.week_start = :tue
126
- dates = @cal.cycles(:every, [:tue, :fri])
127
- assert_equal(10, dates.size)
128
-
129
- dates.each do |date|
130
- assert((date.wday_name == :tue) || (date.wday_name == :fri))
131
- end
132
-
133
- end # should "respond to cycles"
134
-
135
- end # context "week day methods"
136
-
137
- end # context "Koyomi::Calendar"
138
- end
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "test_helper"
4
-
5
- class TestKoyomiDate < Test::Unit::TestCase
6
- context "Koyomi::Date" do
7
- setup do
8
- @date = Date.new(2012, 12, 16)
9
- @wdays = Date::WEEK_WDAYS
10
- end # setup
11
-
12
- should "correct week start, end" do
13
- cal = Koyomi::Calendar.of(@date)
14
-
15
- cal.each do |date|
16
- @wdays.each do |wd|
17
- if (date + 1).wday == @wdays.index(wd)
18
- assert(date.week_end?(wd))
19
- else
20
- assert(!date.week_end?(wd))
21
- end
22
-
23
- if (date).wday == @wdays.index(wd)
24
- assert(date.week_start?(wd))
25
- else
26
- assert(!date.week_start?(wd))
27
- end
28
- end # each wd
29
- end # each date
30
- end # should "correct week end"
31
-
32
- should "respond to nth_wday" do
33
- assert_equal(3, @date.nth_month_week)
34
- end # should "respond to nth_wday"
35
-
36
- should "respond to info" do
37
- assert_equal(3, @date.month_info[:nth])
38
- assert_equal(:sun, @date.month_info[:wday])
39
- end
40
-
41
- end # context "Koyomi::Date"
42
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "test_helper"
4
-
5
- class TestKoyomiMonth < Test::Unit::TestCase
6
- context "Koyomi::Month" do
7
-
8
- setup do
9
- @month = Koyomi::Month.new()
10
- end
11
-
12
- should "have range" do
13
- assert(@month.range.is_a?(Range))
14
- end
15
-
16
- should "respond to next" do
17
- assert(@month.next.is_a?(Koyomi::Month))
18
- end
19
-
20
- should "respond to prev" do
21
- assert(@month.prev.is_a?(Koyomi::Month))
22
- end
23
-
24
- should "respond to nth_wday" do
25
- month = Koyomi::Month.new(12, 2012)
26
- assert_equal(Date.new(2012, 12, 1), month.nth_wday(1, :sat))
27
- end
28
-
29
- should "respond to wdays" do
30
- month = Koyomi::Month.new(12, 2012)
31
- assert_equal(5, @month.wdays(:sat).size)
32
- assert_equal(4, @month.wdays(:fri).size)
33
- end # should "respond to wdays"
34
-
35
- should "respond to cycles" do
36
- month = Koyomi::Month.new(12, 2012)
37
-
38
- assert_equal(4, month.cycles([1,3], [:tue, :fri]).size)
39
-
40
- dates = month.cycles(:every, [:mon, :thu])
41
- assert_equal(9, dates.size)
42
-
43
- dates = month.cycles(:every, [:mon, :sun])
44
- assert_equal(10, dates.size)
45
- end
46
-
47
- end # context "Koyomi::Month"
48
- end
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "test_helper"
4
-
5
- class TestKoyomiWeek < Test::Unit::TestCase
6
- context "Koyomi::Week" do
7
-
8
- setup do
9
- @today = Date.today
10
- @year = @today.year
11
- @month = @today.month
12
- end # setup
13
-
14
- should "generate week instance" do
15
- assert_nothing_raised(Exception) do
16
- @week = Koyomi::Week.new(@today, Koyomi::Week::DEFAULT_START)
17
- end
18
- end # should "generate week instance"
19
-
20
- should "calcurate windex" do
21
- date = Date.new(2012, 12, 23)
22
- assert(Koyomi::Week.windex(:sun) == (date).wday)
23
- assert(Koyomi::Week.windex(:mon) == (date + 1).wday)
24
- assert(Koyomi::Week.windex(:tue) == (date + 2).wday)
25
- assert(Koyomi::Week.windex(:wed) == (date + 3).wday)
26
- assert(Koyomi::Week.windex(:thu) == (date + 4).wday)
27
- assert(Koyomi::Week.windex(:fri) == (date + 5).wday)
28
- assert(Koyomi::Week.windex(:sat) == (date + 6).wday)
29
- end
30
-
31
- should "start specified week day" do
32
- date = Date.new(2012, 12, 23)
33
- Koyomi::Week::WDAYS.each do |wday|
34
- assert_equal(Koyomi::Week.windex(wday), Koyomi::Week.new(date, wday).range.first.wday)
35
- end
36
- end
37
-
38
- should "respond date to request of week day" do
39
- date = Date.new(2012, 12, 23)
40
- Koyomi::Week::WDAYS.each do |wday|
41
- assert_equal(Koyomi::Week.windex(wday), Koyomi::Week.new(date, wday).__send__(wday).wday)
42
- end
43
- end
44
-
45
- end # context "Koyomi::Week"
46
- end