timeboss 0.0.7 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.gitignore +5 -3
  5. data/.yardopts +1 -0
  6. data/CODE_OF_CONDUCT.md +76 -0
  7. data/README.md +30 -18
  8. data/bin/tbsh +15 -0
  9. data/lib/tasks/calendars.rake +5 -0
  10. data/lib/timeboss.rb +4 -0
  11. data/lib/timeboss/calendar.rb +21 -0
  12. data/lib/timeboss/calendar/day.rb +18 -6
  13. data/lib/timeboss/calendar/half.rb +6 -2
  14. data/lib/timeboss/calendar/month.rb +6 -2
  15. data/lib/timeboss/calendar/period.rb +25 -11
  16. data/lib/timeboss/calendar/quarter.rb +6 -2
  17. data/lib/timeboss/calendar/support/formatter.rb +3 -2
  18. data/lib/timeboss/calendar/support/month_basis.rb +1 -0
  19. data/lib/timeboss/calendar/support/{month_based.rb → monthly_unit.rb} +22 -18
  20. data/lib/timeboss/calendar/support/navigable.rb +72 -0
  21. data/lib/timeboss/calendar/support/shiftable.rb +218 -28
  22. data/lib/timeboss/calendar/support/translatable.rb +92 -0
  23. data/lib/timeboss/calendar/support/unit.rb +27 -0
  24. data/lib/timeboss/calendar/waypoints.rb +5 -80
  25. data/lib/timeboss/calendar/waypoints/absolute.rb +113 -0
  26. data/lib/timeboss/calendar/waypoints/relative.rb +267 -0
  27. data/lib/timeboss/calendar/week.rb +25 -18
  28. data/lib/timeboss/calendar/year.rb +5 -5
  29. data/lib/timeboss/calendars.rb +16 -1
  30. data/lib/timeboss/version.rb +1 -1
  31. data/spec/calendar/day_spec.rb +1 -1
  32. data/spec/calendar/support/{month_based_spec.rb → monthly_unit_spec.rb} +18 -8
  33. data/spec/calendar/week_spec.rb +5 -13
  34. data/spec/calendars/broadcast_spec.rb +27 -7
  35. data/spec/calendars_spec.rb +7 -1
  36. data/timeboss.gemspec +1 -0
  37. metadata +32 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0993a0cd3f9eaf4c63e71aac4b816950c7454d7cdbebb41032d4d52ed401fa9f'
4
- data.tar.gz: 7b3ecd196897915c0ca137b21d2e70b3004513098fe1c880e7847106529f5e8b
3
+ metadata.gz: b27f1fec825b8ddb084a029a0621d939bd2525a67f33879611dfc36f6a722d4c
4
+ data.tar.gz: 93fb0c6366dab6a4e577c1507d8cb99ddbb952ebfeea5ec67f134d1ba0c33c14
5
5
  SHA512:
6
- metadata.gz: 9e57840bb1b2645a1247a9868840abb1b1eed60de9106115b8a103aac7ee4689c476d0cbf44ac9596e1ff5ce538caa23666bcaedf85d732d84cd14d71671fde4
7
- data.tar.gz: 6fd2d42323c56dd3af20a1312c993fa31ac7652cc01826fff856529ef2019c8b66da0d9b47b0563c3a8753ab15de84e6321e2a465d02611886fccc533ccfa3ce
6
+ metadata.gz: dab7d412003da6fd0b753e49a46c8d877f15cf802997fa3ad172ad48b2fd571aeb9288572254bf8b4a9289f4eccdaef2f6cc1d88e4a0d0512beea946022fe7df
7
+ data.tar.gz: 197ae44718c8dca52c091d90ab6c0a80f0e45d3207b095ff8194801b06481f20efabb6612ba822270c682429da12b16c0e08c87b91ff7e0b72440dcf8b3573ee
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: kevinstuffandthings
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior.
15
+
16
+ **Expected behavior**
17
+ A clear and concise description of what you expected to happen.
18
+
19
+ **Logs**
20
+ If applicable, add code/outputs to help explain your problem.
21
+
22
+ **Additional context**
23
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: kevinstuffandthings
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
- /*.gem
2
- /Gemfile.lock
3
- /.bundle
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ .yardoc
5
+ doc
@@ -0,0 +1 @@
1
+ --protected lib/**/*.rb
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kevinstuffandthings@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/README.md CHANGED
@@ -1,31 +1,32 @@
1
- # TimeBoss [![Build Status](https://travis-ci.com/kevinstuffandthings/timeboss.svg?branch=master)](https://travis-ci.com/kevinstuffandthings/timeboss)
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
2
  A gem providing convenient navigation of the [Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar).
3
-
4
- _This is a work in progress. Check back soon for the initial release!_
3
+ Originally developed for [Simulmedia](https://simulmedia.com).
5
4
 
6
5
  ## Installation
7
6
  Add this line to your application's Gemfile:
7
+
8
8
  ```ruby
9
9
  # update with the version of your choice
10
10
  gem 'timeboss'
11
11
  ```
12
12
 
13
13
  And then execute:
14
+
14
15
  ```bash
15
16
  $ bundle install
16
17
  ```
17
18
 
18
19
  Or install it yourself as:
20
+
19
21
  ```bash
20
22
  $ gem install timeboss
21
23
  ```
22
24
 
23
- You can find the gem on [RubyGems](https://rubygems.org/gems/timeboss).
24
-
25
25
  ## Usage
26
26
  Supports `year`, `half`, `quarter`, `month`, `week`, and `day`.
27
27
 
28
28
  Prepare your calendar for use:
29
+
29
30
  ```ruby
30
31
  require 'timeboss/calendars/broadcast'
31
32
 
@@ -34,6 +35,7 @@ calendar = TimeBoss::Calendars::Broadcast.new
34
35
  ```
35
36
 
36
37
  You can ask simple questions of the calendar:
38
+
37
39
  ```ruby
38
40
  period = calendar.parse('2019Q4') # or '2018', or '2019-12-21', or '2020W32', or '2020M3W2'
39
41
  # => #<TimeBoss::Calendar::Quarter:0x007f82d50e2478>
@@ -60,11 +62,12 @@ calendar.years_back(2).map { |y| y.start_date.to_s } # run in 2020
60
62
  calendar.months_ago(3).name # run in 2020M7
61
63
  # => "2020M4"
62
64
 
63
- calendar.weeks_hence(3).name # run in 2020W29
65
+ calendar.weeks_ahead(3).name # run in 2020W29
64
66
  # => "2020W32"
65
67
  ```
66
68
 
67
69
  The resulting periods can be formatted a variety of (parsable) ways:
70
+
68
71
  ```ruby
69
72
  entry = calendar.parse('2020M24')
70
73
  entry.format
@@ -76,9 +79,11 @@ entry.format(:quarter)
76
79
  entry.format(:quarter, :month)
77
80
  # => "2020Q2M3W2"
78
81
  ```
82
+
79
83
  _Note: all parsable descriptors should be ordered by chronological specificity (from least to most)_
80
84
 
81
85
  Each type of period can give you information about its constituent periods:
86
+
82
87
  ```ruby
83
88
  calendar.this_month.weeks.map(&:to_s)
84
89
  # => ["2020M1W1: 2019-12-30 thru 2020-01-05", "2020M1W2: 2020-01-06 thru 2020-01-12", "2020M1W3: 2020-01-13 thru 2020-01-19", "2020M1W4: 2020-01-20 thru 2020-01-26"]
@@ -94,6 +99,7 @@ calendar.parse('2020Q1').months.map(&:name)
94
99
  ```
95
100
 
96
101
  Period shifting is easy. Note that the shifts are relative to today, not the base date. A shift examines the base period to find its offset into the shifting period size, and project it relative to now.
102
+
97
103
  ```ruby
98
104
  calendar.parse('Q3').years_ago(5).title
99
105
  # => "Q3 2015"
@@ -112,6 +118,7 @@ calendar.this_week.next_year.to_s # run 2020W29
112
118
  ```
113
119
 
114
120
  Complicated range expressions can be parsed using the `..` range operator, or evaluated with `thru`:
121
+
115
122
  ```ruby
116
123
  calendar.parse('2020M1 .. 2020M2').weeks.map(&:title)
117
124
  # => ["Week of December 30, 2019", "Week of January 6, 2020", "Week of January 13, 2020", "Week of January 20, 2020", "Week of January 27, 2020", "Week of February 3, 2020", "Week of February 10, 2020", "Week of February 17, 2020"]
@@ -127,10 +134,11 @@ period = calendar.parse('2020W3..2020Q1')
127
134
  The examples above are just samples. Try different periods, operators, etc.
128
135
 
129
136
  ### Shell
130
- To open an IRB shell for the broadcast calendar, use the `timeboss:calendars:broadcast:shell` rake task.
137
+ To open an IRB shell for the broadcast calendar, use the `tbsh` executable, or the `timeboss:calendars:broadcast:shell` rake task.
131
138
  You will find yourself in the context of an instantiated `TimeBoss::Calendars::Broadcast` object:
139
+
132
140
  ```bash
133
- $ rake timeboss:calendars:broadcast:shell
141
+ $ tbsh
134
142
  2.4.1 :001 > next_quarter
135
143
  => #<TimeBoss::Calendar::Quarter:0x007fe04c16a1c8 @calendar=#<TimeBoss::Calendars::Broadcast:0x007fe04c1a0458 @basis=TimeBoss::Calendars::Broadcast::Basis>, @year_index=2020, @index=4, @start_date=#<Date: 2020-09-28 ((2459121j,0s,0n),+0s,2299161j)>, @end_date=#<Date: 2020-12-27 ((2459211j,0s,0n),+0s,2299161j)>>
136
144
  2.4.1 :002 > last_year
@@ -194,17 +202,21 @@ end
194
202
  ```
195
203
 
196
204
  With the new calendar implemented, it can be accessed in one of 2 ways:
205
+
197
206
  - via traditional instantiation:
198
- ```ruby
199
- calendar = MyCalendars::AugustFiscal.new
200
- calendar.this_year
201
- ```
207
+
208
+ ```ruby
209
+ calendar = MyCalendars::AugustFiscal.new
210
+ calendar.this_year
211
+ ```
212
+
202
213
  - via `TimeBoss::Calendars`:
203
- ```ruby
204
- require 'timeboss/calendars'
205
- calendar = TimeBoss::Calendars[:august_fiscal]
206
- calendar.this_year
207
- ```
214
+
215
+ ```ruby
216
+ require 'timeboss/calendars'
217
+ calendar = TimeBoss::Calendars[:august_fiscal]
218
+ calendar.this_year
219
+ ```
208
220
 
209
221
  ## TODO
210
- - [x] Add gem deployment via [Travis-CI](https://docs.travis-ci.com/user/deployment/rubygems/#:~:text=Travis%20CI%20can%20automatically%20release,RubyGems%20after%20a%20successful%20build.&text=If%20you%20tag%20a%20commit,tags%20are%20uploaded%20to%20GitHub.&text=You%20will%20be%20prompted%20to,key%20on%20the%20command%20line.)
222
+ - [ ] Add comprehensive documentation
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'timeboss/calendars'
4
+ require 'timeboss/support/shellable'
5
+
6
+ calendar = if ARGV.length == 1
7
+ TimeBoss::Calendars[ARGV.first]&.calendar
8
+ else
9
+ TimeBoss::Calendars.first.calendar
10
+ end
11
+
12
+ abort "Unknown calendar" if calendar.nil?
13
+
14
+ puts "Active calendar: #{calendar.title}"
15
+ TimeBoss::Support::Shellable.open(calendar)
@@ -4,6 +4,11 @@ namespace :timeboss do
4
4
  namespace :calendars do
5
5
  TimeBoss::Calendars.each do |entry|
6
6
  namespace entry.name do
7
+ desc "Evaluate an expression for the #{entry.name} calendar"
8
+ task :evaluate, %i[expression] => ['timeboss:init'] do |_, args|
9
+ puts entry.calendar.parse(args[:expression])
10
+ end
11
+
7
12
  desc "Open a shell with the #{entry.name} calendar"
8
13
  task shell: ['timeboss:init'] do
9
14
  require 'timeboss/support/shellable'
@@ -1,2 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "timeboss/version"
3
+
4
+ # TimeBoss
5
+ module TimeBoss
6
+ end
@@ -9,8 +9,29 @@ require_relative './calendar/support/month_basis'
9
9
  module TimeBoss
10
10
  class Calendar
11
11
  include Waypoints
12
+
13
+ # @!method parse
14
+ # Parse an identifier into a unit or period.
15
+ # Valid identifiers can include simple units (like "2020Q3", "2020M8W3", "last_quarter"),
16
+ # mathematical expressions (like "this_month+6"),
17
+ # or period expressions (like "2020W1..2020W8", "this_quarter-2..next_quarter")
18
+ # @param identifier [String]
19
+ # @return [Support::Unit, Period]
20
+
12
21
  delegate :parse, to: :parser
13
22
 
23
+ # Get a name by which this calendar can be referenced.
24
+ # @return [String]
25
+ def name
26
+ self.class.to_s.demodulize.underscore
27
+ end
28
+
29
+ # Get a friendly title for this calendar.
30
+ # @return [String]
31
+ def title
32
+ name.titleize
33
+ end
34
+
14
35
  protected
15
36
 
16
37
  attr_reader :basis
@@ -8,27 +8,39 @@ module TimeBoss
8
8
  super(calendar, start_date, start_date)
9
9
  end
10
10
 
11
+ # Get a simple representation of this day.
12
+ # @return [String] (e.g. "2020-08-03")
11
13
  def name
12
14
  start_date.to_s
13
15
  end
14
16
 
17
+ # Get a "pretty" representation of this day.
18
+ # @return [String] (e.g. "August 3, 2020")
15
19
  def title
16
20
  start_date.strftime('%B %-d, %Y')
17
21
  end
18
22
 
19
- def to_s
20
- name
21
- end
23
+ alias_method :to_s, :name
22
24
 
25
+ # Get the index of this day within its containing year.
26
+ # @return [Integer]
23
27
  def index
24
- @_index ||= (start_date - calendar.year_for(start_date).start_date).to_i + 1
28
+ @_index ||= (start_date - year.start_date).to_i + 1
29
+ end
30
+
31
+ # Get the year number for this day.
32
+ # @return [Integer] (e.g. 2020)
33
+ def year_index
34
+ @_year_index ||= year.year_index
25
35
  end
26
36
 
27
- def previous
37
+ private
38
+
39
+ def down
28
40
  self.class.new(calendar, start_date - 1.day)
29
41
  end
30
42
 
31
- def next
43
+ def up
32
44
  self.class.new(calendar, start_date + 1.day)
33
45
  end
34
46
  end
@@ -1,15 +1,19 @@
1
1
  # frozen_string_literal: true
2
- require_relative './support/month_based'
2
+ require_relative './support/monthly_unit'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
6
- class Half < Support::MonthBased
6
+ class Half < Support::MonthlyUnit
7
7
  NUM_MONTHS = 6
8
8
 
9
+ # Get a simple representation of this half.
10
+ # @return [String] (e.g. "2020H2")
9
11
  def name
10
12
  "#{year_index}H#{index}"
11
13
  end
12
14
 
15
+ # Get a "pretty" representation of this half.
16
+ # @return [String] (e.g. "H2 2020")
13
17
  def title
14
18
  "H#{index} #{year_index}"
15
19
  end
@@ -1,15 +1,19 @@
1
1
  # frozen_string_literal: true
2
- require_relative './support/month_based'
2
+ require_relative './support/monthly_unit'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
6
- class Month < Support::MonthBased
6
+ class Month < Support::MonthlyUnit
7
7
  NUM_MONTHS = 1
8
8
 
9
+ # Get a simple representation of this month.
10
+ # @return [String] (e.g. "2020M8")
9
11
  def name
10
12
  "#{year_index}M#{index}"
11
13
  end
12
14
 
15
+ # Get a "pretty" representation of this month.
16
+ # @return [String] (e.g. "August 2020")
13
17
  def title
14
18
  "#{Date::MONTHNAMES[index]} #{year_index}"
15
19
  end
@@ -3,9 +3,29 @@ module TimeBoss
3
3
  class Calendar
4
4
  class Period
5
5
  attr_reader :begin, :end
6
+
7
+ # @!method start_date
8
+ # Get the start date of this period.
9
+ # @return [Date]
6
10
  delegate :start_date, to: :begin
11
+
12
+ # @!method end_date
13
+ # Get the end date of this period.
14
+ # @return [Date]
7
15
  delegate :end_date, to: :end
8
16
 
17
+ # @!method name
18
+ # Get a simple representation of this period.
19
+ # @return [String]
20
+
21
+ # @!method title
22
+ # Get a "pretty" representation of this period.
23
+ # @return [String]
24
+
25
+ # @!method to_s
26
+ # Get a stringified representation of this period.
27
+ # @return [String]
28
+
9
29
  %i[name title to_s].each do |message|
10
30
  define_method(message) do
11
31
  text = self.begin.send(message)
@@ -14,7 +34,7 @@ module TimeBoss
14
34
  end
15
35
  end
16
36
 
17
- %w[week month quarter half year].each do |size|
37
+ %w[day week month quarter half year].each do |size|
18
38
  define_method(size.pluralize) do
19
39
  entry = calendar.send("#{size}_for", self.begin.start_date)
20
40
  build_entries entry
@@ -27,20 +47,14 @@ module TimeBoss
27
47
  end
28
48
  end
29
49
 
50
+ # Does this period cover the current date?
51
+ # @return [Boolean]
30
52
  def current?
31
53
  to_range.include?(Date.today)
32
54
  end
33
55
 
34
- def days
35
- to_range.map { |d| Day.new(calendar, d) }
36
- end
37
-
38
- def day
39
- entries = days
40
- return nil unless entries.length == 1
41
- entries.first
42
- end
43
-
56
+ # Express this period as a date range.
57
+ # @return [Range<Date, Date>]
44
58
  def to_range
45
59
  @_to_range ||= start_date .. end_date
46
60
  end