periods 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f213b325b1d0a1f0121ae75fff7f51d98a94ba29
4
- data.tar.gz: d88cb1821b6b0552b6c4ce7d3046e13a4ff7dc59
3
+ metadata.gz: be562d9701b30b7afcfc6dac163ad6e9a7cad181
4
+ data.tar.gz: a57326343a2442706f503dfe46776e5c084fc876
5
5
  SHA512:
6
- metadata.gz: e72c9f950fd4d18d80fb4c0f96dbe3e127eb4ea5250aa6ce5c8d7a71f7a08d936f1d93e318f6510ebbc9a7ec237418a45a5265c6f0a453c4bf9a4d9e121d96f7
7
- data.tar.gz: 550a89717f3a6a21f5827efe343826d676db91f6f235f557e276d5f4b81cc99cf93c83798d8051a4f221df3f99489e7d6812b3a4ea3fa7388718b1ead68e55d9
6
+ metadata.gz: 7d03693f89c82cca815bb05ec1c4a3a03d0250c196a757c6b658dad0c41c47b9aa7d21ab4abb192c562d10f5908da4e1a2b210dfca53832e5a8afb005c6f8b90
7
+ data.tar.gz: 8464da097b035ad3ea932e43450efab9edeefbdf4eac9938652910e8e202e54e7a8a712ad263f38ce80615d0086a67572cf93524ce2f1eb741ad92282dcbad72
data/README.md CHANGED
@@ -164,6 +164,7 @@ A year starts at first day of a month and ends one year later:
164
164
  year.next # => 01.02.2016 - 31.01.2017
165
165
  year.previous # => 01.02.2014 - 31.01.2015
166
166
  year.months # => [Month.for('01.02.2015'), ..., Month.for('01.01.2016')]
167
+ year.quarters # => [Quarter.for('01.02.2015'), ..., Quarter.for('01.11.2015')]
167
168
 
168
169
  ### If constants already exist
169
170
 
@@ -197,6 +198,7 @@ Write your own classes:
197
198
  * Use Time not Date
198
199
  * Optimize README
199
200
  * Comment Code
201
+ * Provide helper methods Month('25.06.2015'), Quarter(), ...
200
202
 
201
203
  ## Contributing
202
204
 
@@ -1,4 +1,5 @@
1
1
  require 'periods/period'
2
+ require 'periods/null_period'
2
3
  require 'periods/month'
3
4
  require 'periods/monthly_period'
4
5
  require 'periods/quarter'
@@ -1,6 +1,7 @@
1
1
  require 'periods/classes'
2
2
 
3
3
  Period = Periods::Period
4
+ NullPeriod = Periods::NullPeriod
4
5
 
5
6
  Month = Periods::Month
6
7
  MonthlyPeriod = Periods::MonthlyPeriod
@@ -8,26 +8,11 @@ module Periods
8
8
  base.class_eval do
9
9
  include Periods::Modules::HalfyearlyPeriod
10
10
  include InstanceMethods
11
- extend ClassMethods
12
- end
13
- end
14
-
15
- module ClassMethods
16
- ##
17
- # '25.06.2015' => 01.06.2015 - '30.11.2015'
18
- #
19
- def for(date)
20
- new(date)
21
11
  end
22
12
  end
23
13
 
24
14
  module InstanceMethods
25
15
 
26
- def initialize(date)
27
- date = Date.parse(date.to_s)
28
- super(beginning_of_month(date), end_of_month(beginning_of_month(date).next_month(6).prev_day))
29
- end
30
-
31
16
  def months
32
17
  months = [Periods::Month.for(start_date)]
33
18
  1.upto(5) do |idx|
@@ -36,7 +21,15 @@ module Periods
36
21
  months
37
22
  end
38
23
 
24
+ def quarters
25
+ [Periods::Quarter.for(start_date), Periods::Quarter.for(start_date.next_month(3))]
26
+ end
27
+
39
28
  private
29
+ def init_with_date(date)
30
+ init_with_dates(
31
+ beginning_of_month(date), end_of_month(beginning_of_month(date).next_month(6).prev_day))
32
+ end
40
33
 
41
34
  def beginning_of_month(date)
42
35
  Periods::DateCalculator.new(date).beginning_of_month
@@ -1,4 +1,5 @@
1
1
  require 'periods/modules/period'
2
+ require 'periods/modules/single_date_initialize'
2
3
 
3
4
  module Periods
4
5
  module Modules
@@ -7,18 +8,8 @@ module Periods
7
8
  def self.included(base)
8
9
  base.class_eval do
9
10
  include Periods::Modules::Period
11
+ include SingleDateInitialize
10
12
  include InstanceMethods
11
- extend ClassMethods
12
- end
13
- end
14
-
15
- module ClassMethods
16
- ##
17
- # '25.06.2015' => 25.06.2015 - '24.12.2015'
18
- #
19
- def for(date)
20
- date = Date.parse(date.to_s)
21
- new(date, date.next_month(6).prev_day)
22
13
  end
23
14
  end
24
15
 
@@ -35,6 +26,11 @@ module Periods
35
26
  (self.next.start_date - start_date).to_i
36
27
  end
37
28
 
29
+ private
30
+ def init_with_date(date)
31
+ init_with_dates(date, date.next_month(6).prev_day)
32
+ end
33
+
38
34
  end
39
35
  end
40
36
  end
@@ -9,24 +9,11 @@ module Periods
9
9
  base.class_eval do
10
10
  include Periods::Modules::MonthlyPeriod
11
11
  include InstanceMethods
12
- extend ClassMethods
13
- end
14
- end
15
-
16
- module ClassMethods
17
- def for(date)
18
- new(date)
19
12
  end
20
13
  end
21
14
 
22
15
  module InstanceMethods
23
16
 
24
- def initialize(date)
25
- date = Date.parse(date.to_s)
26
- @start_date = beginning_of_month(date)
27
- @end_date = end_of_month(date)
28
- end
29
-
30
17
  def month
31
18
  start_date.month
32
19
  end
@@ -47,6 +34,10 @@ module Periods
47
34
 
48
35
  private
49
36
 
37
+ def init_with_date(date)
38
+ init_with_dates(beginning_of_month(date), end_of_month(date))
39
+ end
40
+
50
41
  def beginning_of_month(date)
51
42
  Periods::DateCalculator.new(date).beginning_of_month
52
43
  end
@@ -1,4 +1,5 @@
1
1
  require 'periods/modules/period'
2
+ require 'periods/modules/single_date_initialize'
2
3
 
3
4
  module Periods
4
5
  module Modules
@@ -7,18 +8,8 @@ module Periods
7
8
  def self.included(base)
8
9
  base.class_eval do
9
10
  include Periods::Modules::Period
11
+ include SingleDateInitialize
10
12
  include InstanceMethods
11
- extend ClassMethods
12
- end
13
- end
14
-
15
- module ClassMethods
16
- ##
17
- # '25.06.2015' => 25.06.2015 - '24.07.2015'
18
- #
19
- def for(date)
20
- date = Date.parse(date.to_s)
21
- new(date, date.next_month.prev_day)
22
13
  end
23
14
  end
24
15
 
@@ -37,6 +28,11 @@ module Periods
37
28
  self.class.for(start_date.prev_month)
38
29
  end
39
30
 
31
+ private
32
+ def init_with_date(date)
33
+ init_with_dates(date, date.next_month.prev_day)
34
+ end
35
+
40
36
  end
41
37
  end
42
38
  end
@@ -0,0 +1,59 @@
1
+ module Periods
2
+ module Modules
3
+ module NullPeriod
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ include Comparable
8
+ include InstanceMethods
9
+ end
10
+ end
11
+
12
+ module InstanceMethods
13
+
14
+ attr_reader :start_date
15
+ attr_reader :end_date
16
+
17
+ def initialize(*args)
18
+ end
19
+
20
+ def ==(period)
21
+ self.class == period.class
22
+ end
23
+
24
+ def <=>(period)
25
+ 0
26
+ end
27
+
28
+ def next
29
+ self
30
+ end
31
+
32
+ def previous
33
+ self
34
+ end
35
+
36
+ def days
37
+ 0
38
+ end
39
+
40
+ def start_year
41
+ 0
42
+ end
43
+
44
+ def end_year
45
+ 0
46
+ end
47
+
48
+ def include?(period)
49
+ false
50
+ end
51
+
52
+ def to_s
53
+ "#{self.class.name}"
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -8,27 +8,13 @@ module Periods
8
8
 
9
9
  def self.included(base)
10
10
  base.class_eval do
11
- include Periods::Modules::Period
12
11
  include Periods::Modules::QuarterlyPeriod
13
12
  include InstanceMethods
14
- extend ClassMethods
15
- end
16
- end
17
-
18
- module ClassMethods
19
- def for(date)
20
- new(date)
21
13
  end
22
14
  end
23
15
 
24
16
  module InstanceMethods
25
17
 
26
- def initialize(date)
27
- date = Date.parse(date.to_s)
28
- @start_date = beginning_of_month(date)
29
- @end_date = end_of_month(@start_date.next_month(2))
30
- end
31
-
32
18
  def months
33
19
  [ Periods::Month.for(start_date),
34
20
  Periods::Month.for(start_date.next_month),
@@ -36,6 +22,9 @@ module Periods
36
22
  end
37
23
 
38
24
  private
25
+ def init_with_date(date)
26
+ init_with_dates(beginning_of_month(date), end_of_month(date.next_month(2)))
27
+ end
39
28
 
40
29
  def beginning_of_month(date)
41
30
  Periods::DateCalculator.new(date).beginning_of_month
@@ -1,5 +1,6 @@
1
1
  require 'periods/date_calculator'
2
2
  require 'periods/modules/period'
3
+ require 'periods/modules/single_date_initialize'
3
4
 
4
5
  module Periods
5
6
  module Modules
@@ -8,18 +9,8 @@ module Periods
8
9
  def self.included(base)
9
10
  base.class_eval do
10
11
  include Periods::Modules::Period
12
+ include SingleDateInitialize
11
13
  include InstanceMethods
12
- extend ClassMethods
13
- end
14
- end
15
-
16
- module ClassMethods
17
- ##
18
- # '25.06.2015' => 25.06.2015 - '24.07.2015'
19
- #
20
- def for(date)
21
- date = Date.parse(date.to_s)
22
- new(date, date.next_month(3).prev_day)
23
14
  end
24
15
  end
25
16
 
@@ -38,6 +29,10 @@ module Periods
38
29
  self.class.for(start_date.prev_month(3))
39
30
  end
40
31
 
32
+ private
33
+ def init_with_date(date)
34
+ init_with_dates(date, date.next_month(3).prev_day)
35
+ end
41
36
  end
42
37
  end
43
38
  end
@@ -0,0 +1,55 @@
1
+ module Periods
2
+ module Modules
3
+ module SingleDateInitialize
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ extend ClassMethods
8
+ include InstanceMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def for(date)
14
+ new(date)
15
+ end
16
+ end
17
+
18
+ module InstanceMethods
19
+ ##
20
+ # Initialize a new period based on a single given date.
21
+ #
22
+ # @example
23
+ #
24
+ # period = <Class>.new(Date.new(2015,6,25))
25
+ # period = <Class>.new('25.06.2015')
26
+ # period = <Class>.new(<Class>.new('25.06.2015')
27
+ #
28
+ def initialize(date)
29
+ if date.is_a?(self.class)
30
+ init_with_dates(date.start_date, date.end_date)
31
+ elsif date.is_a?(Date)
32
+ init_with_date(date)
33
+ elsif date.is_a?(String)
34
+ init_with_date(Date.parse(date.to_s))
35
+ elsif date.is_a?(Time)
36
+ init_with_date(Date.parse(date.to_s))
37
+ else
38
+ raise ArgumentError, "#{self.class} cannot be initialized with #{date.class}"
39
+ end
40
+ end
41
+
42
+ protected
43
+ def init_with_date(date)
44
+ raise "Please implement."
45
+ end
46
+
47
+ private
48
+ def init_with_dates(start_date, end_date)
49
+ @start_date = start_date
50
+ @end_date = end_date
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -9,26 +9,10 @@ module Periods
9
9
  base.class_eval do
10
10
  include Periods::Modules::YearlyPeriod
11
11
  include InstanceMethods
12
- extend ClassMethods
13
- end
14
- end
15
-
16
- module ClassMethods
17
- ##
18
- # '25.06.2015' => 01.06.2015 - '30.05.2016'
19
- #
20
- def for(date)
21
- new(date)
22
12
  end
23
13
  end
24
14
 
25
15
  module InstanceMethods
26
-
27
- def initialize(date)
28
- date = Date.parse(date.to_s)
29
- super(beginning_of_month(date), end_of_month(beginning_of_month(date).next_year.prev_day))
30
- end
31
-
32
16
  ##
33
17
  # 01.06.2015 => 01.06.2016
34
18
  #
@@ -55,7 +39,23 @@ module Periods
55
39
  months
56
40
  end
57
41
 
42
+ def quarters
43
+ quarters = [Periods::Quarter.for(start_date)]
44
+ 1.upto(3) do |idx|
45
+ quarters << Periods::Quarter.for(start_date.next_month(idx*3))
46
+ end
47
+ quarters
48
+ end
49
+
50
+ def halfyears
51
+ [Periods::Halfyear.for(start_date), Periods::Halfyear.for(start_date.next_month(6))]
52
+ end
53
+
58
54
  private
55
+ def init_with_date(date)
56
+ init_with_dates(
57
+ beginning_of_month(date), end_of_month(beginning_of_month(date).next_year.prev_day))
58
+ end
59
59
 
60
60
  def beginning_of_month(date)
61
61
  Periods::DateCalculator.new(date).beginning_of_month
@@ -1,4 +1,5 @@
1
1
  require 'periods/modules/period'
2
+ require 'periods/modules/single_date_initialize'
2
3
 
3
4
  module Periods
4
5
  module Modules
@@ -7,18 +8,8 @@ module Periods
7
8
  def self.included(base)
8
9
  base.class_eval do
9
10
  include Periods::Modules::Period
11
+ include SingleDateInitialize
10
12
  include InstanceMethods
11
- extend ClassMethods
12
- end
13
- end
14
-
15
- module ClassMethods
16
- ##
17
- # '25.06.2015' => 25.06.2015 - '24.06.2016'
18
- #
19
- def for(date)
20
- date = Date.parse(date.to_s)
21
- new(date, date.next_year.prev_day)
22
13
  end
23
14
  end
24
15
 
@@ -41,6 +32,11 @@ module Periods
41
32
  (self.next.start_date - start_date).to_i
42
33
  end
43
34
 
35
+ private
36
+ def init_with_date(date)
37
+ init_with_dates(date, date.next_year.prev_day)
38
+ end
39
+
44
40
  end
45
41
  end
46
42
  end
@@ -1,4 +1,5 @@
1
1
  require 'periods/modules/period'
2
+ require 'periods/modules/null_period'
2
3
  require 'periods/modules/month'
3
4
  require 'periods/modules/monthly_period'
4
5
  require 'periods/modules/quarter'
@@ -0,0 +1,9 @@
1
+ require 'periods/modules/null_period'
2
+
3
+ module Periods
4
+ class NullPeriod
5
+ include Periods::Modules::NullPeriod
6
+ end
7
+ end
8
+
9
+
@@ -1,3 +1,3 @@
1
1
  module Periods
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,40 @@
1
+ shared_examples "Initialized by single date" do
2
+
3
+ describe ".for" do
4
+
5
+ context "Date given" do
6
+ it "returns period based on given date" do
7
+ expect(described_class.for(Date.new(2015,6,25))).to eq period
8
+ end
9
+ end
10
+
11
+ context "Time given" do
12
+ it "returns period based on given date" do
13
+ expect(described_class.for(Time.new(2015,6,25,12,13,14))).to eq period
14
+ end
15
+ end
16
+
17
+ context "String given" do
18
+ it "returns period based on given date" do
19
+ expect(described_class.for('25.06.2015')).to eq period
20
+ end
21
+ end
22
+
23
+ context "same class given" do
24
+ it "returns period based on given date" do
25
+ expect(described_class.for(described_class.for('25.06.2015'))).to eq period
26
+ end
27
+ end
28
+
29
+ context "Period given" do
30
+ it "raise exception" do
31
+ expect {
32
+ described_class.for(Period.new('01.01.2015', '01.01.2015'))
33
+ }.to raise_error(ArgumentError)
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+
@@ -1,11 +1,15 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe Halfyear do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
12
+ end
9
13
 
10
14
  describe ".for" do
11
15
  it "returns halfyear of given date included" do
@@ -38,4 +42,13 @@ describe Halfyear do
38
42
  ]
39
43
  end
40
44
  end
45
+
46
+ describe "#quarters" do
47
+ it "returns quarters of halfyear" do
48
+ expect(described_class.for('01.01.2015').quarters).
49
+ to eq [ Quarter.for('01.01.2015'), Quarter.for('01.04.2015')]
50
+ expect(described_class.for('01.06.2015').quarters).
51
+ to eq [ Quarter.for('01.06.2015'), Quarter.for('01.09.2015')]
52
+ end
53
+ end
41
54
  end
@@ -1,19 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe HalfyearlyPeriod do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
9
-
10
- describe ".for" do
11
- it "returns halfyear of given date included" do
12
- period = described_class.for('25.06.2015')
13
-
14
- expect(period.start_date).to eq Date('25.06.2015')
15
- expect(period.end_date).to eq Date('24.12.2015')
16
- end
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
17
12
  end
18
13
 
19
14
  describe "#next" do
@@ -1,19 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe Month do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
9
-
10
- describe ".for" do
11
- it "returns month of given date included" do
12
- month = described_class.for('25.06.2015')
13
-
14
- expect(month.start_date).to eq Date('01.06.2015')
15
- expect(month.end_date).to eq Date('30.06.2015')
16
- end
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
17
12
  end
18
13
 
19
14
  describe "#next" do
@@ -1,18 +1,50 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe MonthlyPeriod do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
12
+ end
9
13
 
10
14
  describe ".for" do
11
- it "returns month of given date included" do
12
- month = described_class.for('25.06.2015')
15
+ context "Date given" do
16
+ it "returns month of given date included" do
17
+ month = described_class.for(Date.new(2015,6,25))
18
+
19
+ expect(month.start_date).to eq Date('25.06.2015')
20
+ expect(month.end_date).to eq Date('24.07.2015')
21
+ end
22
+ end
23
+
24
+ context "String given" do
25
+ it "returns month of given date included" do
26
+ month = described_class.for('25.06.2015')
27
+
28
+ expect(month.start_date).to eq Date('25.06.2015')
29
+ expect(month.end_date).to eq Date('24.07.2015')
30
+ end
31
+ end
32
+
33
+ context "MonthlyPeriod given" do
34
+ it "returns month of given date included" do
35
+ period = described_class.for(described_class.for('25.06.2015'))
36
+
37
+ expect(period.start_date).to eq Date('25.06.2015')
38
+ expect(period.end_date).to eq Date('24.07.2015')
39
+ end
40
+ end
13
41
 
14
- expect(month.start_date).to eq Date('25.06.2015')
15
- expect(month.end_date).to eq Date('24.07.2015')
42
+ context "Period given" do
43
+ it "raise exception" do
44
+ expect {
45
+ described_class.for(Period.new('25.06.2015', '24.07.2015'))
46
+ }.to raise_error(ArgumentError)
47
+ end
16
48
  end
17
49
  end
18
50
 
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'periods/constants'
3
+
4
+ describe NullPeriod do
5
+
6
+ def new_period(*args)
7
+ described_class.new(*args)
8
+ end
9
+
10
+ describe ".new" do
11
+ it "returns instance with not defined dates" do
12
+ period = described_class.new('25.06.2015', '20.05.2016')
13
+
14
+ expect(period.start_date).to be_nil
15
+ expect(period.end_date).to be_nil
16
+ end
17
+ end
18
+
19
+ describe "==" do
20
+ context "same period given" do
21
+ it "returns true" do
22
+ expect(new_period == new_period).to be_truthy
23
+ end
24
+ end
25
+
26
+ context "not same period given" do
27
+ it "returns false" do
28
+ expect(new_period("02.02.2015", "28.02.2015") == Period.new("02.02.2015", "28.02.2015")).to be_falsey
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "comparing" do
34
+ it "compare correctly" do
35
+ expect(new_period("01.02.2015", "28.02.2015") >= new_period("01.02.2015", "28.02.2015")).to be_truthy
36
+ expect(new_period("01.02.2015", "28.02.2015") > new_period("01.01.2015", "31.01.2015")).to be_falsey
37
+ expect(new_period("01.02.2015", "28.02.2015") <= new_period("01.02.2015", "28.02.2015")).to be_truthy
38
+ expect(new_period("01.02.2015", "28.02.2015") < new_period("01.03.2015", "31.03.2015")).to be_falsey
39
+ end
40
+ end
41
+
42
+ describe "#next" do
43
+ it "returns next period" do
44
+ expect(new_period.next).to eq new_period
45
+ end
46
+ end
47
+
48
+ describe "#previous" do
49
+ it "returns previous period" do
50
+ expect(new_period.previous).to eq new_period
51
+ end
52
+ end
53
+
54
+ describe "#days" do
55
+ it "returns days of period" do
56
+ expect(new_period("25.06.2015", "19.08.2015").days).to eq 0
57
+ end
58
+ end
59
+
60
+ describe "#start_year" do
61
+ it "returns start year of quarter" do
62
+ expect(new_period("25.06.2015", "19.08.2015").start_year).to eq 0
63
+ end
64
+ end
65
+
66
+ describe "#end_year" do
67
+ it "returns end year of quarter" do
68
+ expect(new_period("25.06.2015", "20.05.2016").end_year).to eq 0
69
+ end
70
+ end
71
+
72
+ describe "#include?" do
73
+ context "date included" do
74
+ it "returns true" do
75
+ expect(new_period("01.02.2015", "28.02.2015").include?(Date("01.02.2015"))).to be_falsey
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+
82
+
@@ -1,19 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe Quarter do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
9
-
10
- describe ".for" do
11
- it "returns quarter of given date included" do
12
- period = described_class.for('25.06.2015')
13
-
14
- expect(period.start_date).to eq Date('01.06.2015')
15
- expect(period.end_date).to eq Date('31.08.2015')
16
- end
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
17
12
  end
18
13
 
19
14
  describe "#next" do
@@ -1,19 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe QuarterlyPeriod do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
9
-
10
- describe ".for" do
11
- it "returns quarter of given date included" do
12
- period = described_class.for('25.06.2015')
13
-
14
- expect(period.start_date).to eq Date('25.06.2015')
15
- expect(period.end_date).to eq Date('24.09.2015')
16
- end
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
17
12
  end
18
13
 
19
14
  describe "#next" do
@@ -1,19 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe Year do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
9
-
10
- describe ".for" do
11
- it "returns year of given date included" do
12
- year = described_class.for('25.06.2015')
13
-
14
- expect(year.start_date).to eq Date('01.06.2015')
15
- expect(year.end_date).to eq Date('31.05.2016')
16
- end
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
17
12
  end
18
13
 
19
14
  describe "#next" do
@@ -40,4 +35,24 @@ describe Year do
40
35
  ]
41
36
  end
42
37
  end
38
+
39
+ describe "#quarters" do
40
+ it "returns quarters of year" do
41
+ expect(described_class.for('01.01.2015').quarters).
42
+ to eq [ Quarter.for('01.01.2015'), Quarter.for('01.04.2015'),
43
+ Quarter.for('01.07.2015'), Quarter.for('01.10.2015')]
44
+ expect(described_class.for('01.06.2015').quarters).
45
+ to eq [ Quarter.for('01.06.2015'), Quarter.for('01.09.2015'),
46
+ Quarter.for('01.12.2015'), Quarter.for('01.03.2016')]
47
+ end
48
+ end
49
+
50
+ describe "#halfyears" do
51
+ it "returns halfyears of year" do
52
+ expect(described_class.for('01.01.2015').halfyears).
53
+ to eq [ Halfyear.for('01.01.2015'), Halfyear.for('01.07.2015')]
54
+ expect(described_class.for('01.06.2015').halfyears).
55
+ to eq [ Halfyear.for('01.06.2015'), Halfyear.for('01.12.2015')]
56
+ end
57
+ end
43
58
  end
@@ -1,19 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'periods/constants'
3
+ require 'initialized_by_single_date'
3
4
 
4
5
  describe YearlyPeriod do
5
6
 
6
7
  let(:subject) { described_class.for("1.1.2015") }
7
8
 
8
9
  it_behaves_like "Lint Check"
9
-
10
- describe ".for" do
11
- it "returns year of given date included" do
12
- period = described_class.for('25.06.2015')
13
-
14
- expect(period.start_date).to eq Date('25.06.2015')
15
- expect(period.end_date).to eq Date('24.06.2016')
16
- end
10
+ it_behaves_like "Initialized by single date" do
11
+ let(:period) { described_class.for(Date.new(2015,6,25)) }
17
12
  end
18
13
 
19
14
  describe "#next" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Baustert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,13 +79,16 @@ files:
79
79
  - lib/periods/modules/halfyearly_period.rb
80
80
  - lib/periods/modules/month.rb
81
81
  - lib/periods/modules/monthly_period.rb
82
+ - lib/periods/modules/null_period.rb
82
83
  - lib/periods/modules/period.rb
83
84
  - lib/periods/modules/quarter.rb
84
85
  - lib/periods/modules/quarterly_period.rb
86
+ - lib/periods/modules/single_date_initialize.rb
85
87
  - lib/periods/modules/year.rb
86
88
  - lib/periods/modules/yearly_period.rb
87
89
  - lib/periods/month.rb
88
90
  - lib/periods/monthly_period.rb
91
+ - lib/periods/null_period.rb
89
92
  - lib/periods/period.rb
90
93
  - lib/periods/quarter.rb
91
94
  - lib/periods/quarterly_period.rb
@@ -93,11 +96,13 @@ files:
93
96
  - lib/periods/year.rb
94
97
  - lib/periods/yearly_period.rb
95
98
  - periods.gemspec
99
+ - spec/initialized_by_single_date.rb
96
100
  - spec/lib/halfyear_spec.rb
97
101
  - spec/lib/halfyearly_period_spec.rb
98
102
  - spec/lib/january_spec.rb
99
103
  - spec/lib/month_spec.rb
100
104
  - spec/lib/monthly_period_spec.rb
105
+ - spec/lib/null_period_spec.rb
101
106
  - spec/lib/own_class_spec.rb
102
107
  - spec/lib/period_spec.rb
103
108
  - spec/lib/periods/date_calculator_spec.rb
@@ -132,11 +137,13 @@ signing_key:
132
137
  specification_version: 4
133
138
  summary: Simple period types like Week, Month, Quarter, Halfyear, Year.
134
139
  test_files:
140
+ - spec/initialized_by_single_date.rb
135
141
  - spec/lib/halfyear_spec.rb
136
142
  - spec/lib/halfyearly_period_spec.rb
137
143
  - spec/lib/january_spec.rb
138
144
  - spec/lib/month_spec.rb
139
145
  - spec/lib/monthly_period_spec.rb
146
+ - spec/lib/null_period_spec.rb
140
147
  - spec/lib/own_class_spec.rb
141
148
  - spec/lib/period_spec.rb
142
149
  - spec/lib/periods/date_calculator_spec.rb