timeboss 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.replit +1 -1
- data/README.md +4 -0
- data/lib/timeboss/calendar.rb +6 -0
- data/lib/timeboss/calendar/parser.rb +1 -1
- data/lib/timeboss/calendar/support/month_basis.rb +2 -0
- data/lib/timeboss/calendars.rb +14 -7
- data/lib/timeboss/calendars/broadcast.rb +2 -0
- data/lib/timeboss/calendars/gregorian.rb +2 -0
- data/lib/timeboss/version.rb +1 -1
- data/spec/calendars_spec.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a66336923993e3b4319dd8d0dc925d936ba7e6897f50f1c679a23f37a35e8f8
|
4
|
+
data.tar.gz: 3925a5fd244c6fac67ba026f0f3738398bc67f6cc75e015f8eea21caf78f5d84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ebf1f8c61e12cd086c33336abca2b5a76ee59cc6117711f166672bd9958c753eb68e38e29ed6aeaccb927520eabaf819da50a62b11879186778f97c982c632
|
7
|
+
data.tar.gz: 5bc4914fb3f90bb391fb0e3bb852d25764f926492fccc74ff4ecc56ba321fbad9030fb3812423d4c2ed8bc2c61b2e79b9def7ed34a7789061a2367f122888da1
|
data/.replit
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
language = "ruby"
|
2
|
-
run = "rake timeboss:calendars:broadcast:repl"
|
2
|
+
run = "bundle exec rake timeboss:calendars:broadcast:repl"
|
data/README.md
CHANGED
@@ -221,6 +221,10 @@ With the new calendar implemented, it can be accessed in one of 2 ways:
|
|
221
221
|
|
222
222
|
```ruby
|
223
223
|
require 'timeboss/calendars'
|
224
|
+
TimeBoss::Calendars.register(:august_fiscal, MyCalendars::AugustFiscal)
|
225
|
+
|
226
|
+
# You'll get a cached instance of your calendar here.
|
227
|
+
# Handy when switching back and forth between different calendar implementations.
|
224
228
|
calendar = TimeBoss::Calendars[:august_fiscal]
|
225
229
|
calendar.this_year
|
226
230
|
```
|
data/lib/timeboss/calendar.rb
CHANGED
@@ -41,6 +41,12 @@ module TimeBoss
|
|
41
41
|
true
|
42
42
|
end
|
43
43
|
|
44
|
+
def self.register!
|
45
|
+
return unless TimeBoss::Calendars.method_defined?(:register)
|
46
|
+
TimeBoss::Calendars.register(self.name.to_s.demodulize.underscore, self)
|
47
|
+
end
|
48
|
+
private_class_method :register!
|
49
|
+
|
44
50
|
protected
|
45
51
|
|
46
52
|
attr_reader :basis
|
@@ -11,7 +11,7 @@ module TimeBoss
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def parse(identifier = nil)
|
14
|
-
return nil unless identifier.
|
14
|
+
return nil unless (identifier || '').strip.length > 0
|
15
15
|
return parse_identifier(identifier) unless identifier&.include?(RANGE_DELIMITER)
|
16
16
|
bases = identifier.split(RANGE_DELIMITER).map { |i| parse_identifier(i.strip) } unless identifier.nil?
|
17
17
|
bases ||= [parse_identifier(nil)]
|
@@ -2,6 +2,8 @@ module TimeBoss
|
|
2
2
|
class Calendar
|
3
3
|
module Support
|
4
4
|
# @abstract
|
5
|
+
# A MonthBasis must define a `#start_date` and `#end_date` method.
|
6
|
+
# These methods should be calculated based on the incoming `#year` and `#month` values.
|
5
7
|
class MonthBasis
|
6
8
|
attr_reader :year, :month
|
7
9
|
|
data/lib/timeboss/calendars.rb
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'active_support/core_ext/class/subclasses'
|
3
2
|
require_relative 'calendar'
|
4
3
|
|
5
|
-
Dir[File.expand_path('../calendars/*.rb', __FILE__)].each { |f| require f }
|
6
|
-
|
7
4
|
module TimeBoss
|
8
5
|
module Calendars
|
9
6
|
extend self
|
10
7
|
extend Enumerable
|
11
8
|
delegate :each, :length, to: :all
|
12
9
|
|
10
|
+
# Register a new calendar
|
11
|
+
# @return [Entry]
|
12
|
+
def register(name, klass)
|
13
|
+
Entry.new(name.to_sym, klass).tap do |entry|
|
14
|
+
(@entries ||= {})[name.to_sym] = entry
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
13
18
|
# Retrieve a list of all registered calendars.
|
14
19
|
# @return [Array<Entry>]
|
15
20
|
def all
|
16
|
-
|
17
|
-
|
18
|
-
end
|
21
|
+
return if @entries.nil?
|
22
|
+
@entries.values.sort_by { |e| e.name.to_s }
|
19
23
|
end
|
20
24
|
|
21
25
|
# Retrieve an instance of the specified named calendar.
|
22
26
|
# @param name [String, Symbol] the name of the calendar to retrieve.
|
23
27
|
# @return [Calendar]
|
24
28
|
def [](name)
|
25
|
-
|
29
|
+
return if @entries.nil?
|
30
|
+
@entries[name&.to_sym]&.calendar
|
26
31
|
end
|
27
32
|
|
28
33
|
private
|
@@ -44,3 +49,5 @@ module TimeBoss
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
52
|
+
|
53
|
+
Dir[File.expand_path('../calendars/*.rb', __FILE__)].each { |f| require f }
|
data/lib/timeboss/version.rb
CHANGED
data/spec/calendars_spec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module TimeBoss
|
2
2
|
describe Calendars do
|
3
|
-
class
|
3
|
+
class MyCal < TimeBoss::Calendar
|
4
4
|
def initialize
|
5
5
|
super(basis: nil)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
TimeBoss::Calendars.register(:my_amazing_calendar, MyCal)
|
10
|
+
|
9
11
|
describe '#all' do
|
10
12
|
let(:all) { described_class.all }
|
11
13
|
|
@@ -17,7 +19,7 @@ module TimeBoss
|
|
17
19
|
|
18
20
|
context 'enumerability' do
|
19
21
|
it 'can get a list of names' do
|
20
|
-
expect(described_class.map(&:name)).to include(:broadcast, :
|
22
|
+
expect(described_class.map(&:name)).to include(:broadcast, :my_amazing_calendar)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -34,10 +36,10 @@ module TimeBoss
|
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'can return a new calendar' do
|
37
|
-
c1 = described_class[:
|
38
|
-
expect(c1).to be_instance_of
|
39
|
-
expect(c1.name).to eq '
|
40
|
-
expect(c1.title).to eq 'My
|
39
|
+
c1 = described_class[:my_amazing_calendar]
|
40
|
+
expect(c1).to be_instance_of MyCal
|
41
|
+
expect(c1.name).to eq 'my_cal'
|
42
|
+
expect(c1.title).to eq 'My Cal'
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'can graceully give you nothing' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeboss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McDonald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|