timeboss 0.1.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b27f1fec825b8ddb084a029a0621d939bd2525a67f33879611dfc36f6a722d4c
4
- data.tar.gz: 93fb0c6366dab6a4e577c1507d8cb99ddbb952ebfeea5ec67f134d1ba0c33c14
3
+ metadata.gz: c8b4b4481ef5554103855a604563c4db3a4deddb298af24a219315f1a658c7ba
4
+ data.tar.gz: 8be65df968e3a044a81cf492f3be16a03e9d79a61fb80ac6ff4218c8a5b71aa3
5
5
  SHA512:
6
- metadata.gz: dab7d412003da6fd0b753e49a46c8d877f15cf802997fa3ad172ad48b2fd571aeb9288572254bf8b4a9289f4eccdaef2f6cc1d88e4a0d0512beea946022fe7df
7
- data.tar.gz: 197ae44718c8dca52c091d90ab6c0a80f0e45d3207b095ff8194801b06481f20efabb6612ba822270c682429da12b16c0e08c87b91ff7e0b72440dcf8b3573ee
6
+ metadata.gz: df28f604bbea294960ff8131b65b5b3315bf2cd2c2663866ee3b28e208abc25ef7811535482931620d4886ec8b39249967ed38cfa63cf4a865eba6ea31f11022
7
+ data.tar.gz: 8b8f043b358f21970af342263154ac3bcd40f9322b37c7e7c0587740c703214e77798e8b28ff56d627c9b6bab3f5306bb1e6e21ca52dd7589fa2d6e450a75178
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TimeBoss [![Build Status](https://travis-ci.com/kevinstuffandthings/timeboss.svg?branch=master)](https://travis-ci.com/kevinstuffandthings/timeboss) [![Gem Version](https://badge.fury.io/rb/timeboss.svg)](https://badge.fury.io/rb/timeboss)
2
- A gem providing convenient navigation of the [Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar).
2
+
3
+ A gem providing convenient navigation of the [Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar), the standard Gregorian calendar, and is easily extensible to support multiple financial calendars.
4
+
3
5
  Originally developed for [Simulmedia](https://simulmedia.com).
4
6
 
5
7
  ## Installation
@@ -32,6 +32,10 @@ module TimeBoss
32
32
  name.titleize
33
33
  end
34
34
 
35
+ def supports_weeks?
36
+ false
37
+ end
38
+
35
39
  protected
36
40
 
37
41
  attr_reader :basis
@@ -14,6 +14,7 @@ module TimeBoss
14
14
  def initialize(unit, periods)
15
15
  @unit = unit
16
16
  @periods = PERIODS & periods.map(&:to_sym).push(unit.class.type.to_sym)
17
+ @periods -= [:week] unless unit.calendar.supports_weeks?
17
18
  end
18
19
 
19
20
  def to_s
@@ -13,6 +13,8 @@ module TimeBoss
13
13
  include Shiftable
14
14
  attr_reader :calendar, :start_date, :end_date
15
15
 
16
+ UnsupportedUnitError = Class.new(StandardError)
17
+
16
18
  def self.type
17
19
  self.name.demodulize.underscore
18
20
  end
@@ -5,6 +5,7 @@ module TimeBoss
5
5
  class Calendar
6
6
  class Week < Support::Unit
7
7
  def initialize(calendar, start_date, end_date)
8
+ raise UnsupportedUnitError unless calendar.supports_weeks?
8
9
  super(calendar, start_date, end_date)
9
10
  end
10
11
 
@@ -8,6 +8,10 @@ module TimeBoss
8
8
  super(basis: Basis)
9
9
  end
10
10
 
11
+ def supports_weeks?
12
+ true
13
+ end
14
+
11
15
  private
12
16
 
13
17
  class Basis < Calendar::Support::MonthBasis
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../calendar'
3
+
4
+ module TimeBoss
5
+ module Calendars
6
+ class Gregorian < Calendar
7
+ def initialize
8
+ super(basis: Basis)
9
+ end
10
+
11
+ private
12
+
13
+ class Basis < Calendar::Support::MonthBasis
14
+ def start_date
15
+ @_start_date ||= Date.civil(year, month, 1)
16
+ end
17
+
18
+ def end_date
19
+ @_end_date ||= Date.civil(year, month, -1)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TimeBoss
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
@@ -30,6 +30,7 @@ module TimeBoss
30
30
  before(:each) { allow(calendar).to receive(:year).with(2018).and_return base }
31
31
 
32
32
  it 'can get the relevant weeks for the period' do
33
+ allow(calendar).to receive(:supports_weeks?).and_return true
33
34
  result = subject.weeks
34
35
  result.each { |w| expect(w).to be_instance_of TimeBoss::Calendar::Week }
35
36
  expect(result.map { |w| w.start_date.to_s }).to eq [
@@ -44,6 +45,11 @@ module TimeBoss
44
45
  '2018-08-20'
45
46
  ]
46
47
  end
48
+
49
+ it 'blows up when weeks are not supported' do
50
+ allow(calendar).to receive(:supports_weeks?).and_return false
51
+ expect { subject.weeks }.to raise_error TimeBoss::Calendar::Support::Unit::UnsupportedUnitError
52
+ end
47
53
  end
48
54
 
49
55
  context 'navigation' do
@@ -1,11 +1,16 @@
1
1
  module TimeBoss
2
2
  class Calendar
3
3
  describe Week do
4
- let(:calendar) { instance_double(TimeBoss::Calendar) }
4
+ let(:calendar) { instance_double(TimeBoss::Calendar, supports_weeks?: true) }
5
5
  let(:start_date) { Date.parse('2048-04-06') }
6
6
  let(:end_date) { Date.parse('2048-04-12') }
7
7
  let(:subject) { described_class.new(calendar, start_date, end_date) }
8
8
 
9
+ it "doesn't even exist if its calendar doesn't support weeks" do
10
+ allow(calendar).to receive(:supports_weeks?).and_return false
11
+ expect { subject }.to raise_error TimeBoss::Calendar::Support::Unit::UnsupportedUnitError
12
+ end
13
+
9
14
  it 'knows its stuff' do
10
15
  expect(subject.start_date).to eq start_date
11
16
  expect(subject.end_date).to eq end_date
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeboss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McDonald
@@ -166,6 +166,7 @@ files:
166
166
  - lib/timeboss/calendar/year.rb
167
167
  - lib/timeboss/calendars.rb
168
168
  - lib/timeboss/calendars/broadcast.rb
169
+ - lib/timeboss/calendars/gregorian.rb
169
170
  - lib/timeboss/support/shellable.rb
170
171
  - lib/timeboss/version.rb
171
172
  - spec/calendar/day_spec.rb