timeboss 0.0.8 → 0.0.9

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
  SHA256:
3
- metadata.gz: '082c0c9219e3f40e3e8f98a9850212b678fa895afd0c9062fe4dd21219e879e7'
4
- data.tar.gz: 95f5b7c19bd48f94b458aed504f258a7942daf98e0e5f30d8eed50fdfb572811
3
+ metadata.gz: c9e8eba82ecc236c031a9cd96befc6c3a7454dea1720653426af4db4df227a74
4
+ data.tar.gz: f13fecfd700ffadc07d665addf4d9e7905f042452ede028ab9aa5b517b31bff8
5
5
  SHA512:
6
- metadata.gz: a38a6b535c9b65bb8051e1c54003a05e2ce50c4b1e8d6575ef89f9d7f1ce8976f99b713a8a34e2380c98694696f5b8a4765416631f970ed035c85e7d1744a672
7
- data.tar.gz: 3db1f8f1d6551f9c94c14496f2a13c9133d59ef9352cf638d91b3953a6d17981fef6f70b5a045de259f610cbed8d12fcd109b70df3b3dab08aeaae8b86567d69
6
+ metadata.gz: 860b8b74668c08a9ec37b37ae5c450babc26f0b130342081b40a94eec468af374618f369791a8ebeb31245ddd7e94b7c4a162e505a8924f12c2a9651e5dad1c2
7
+ data.tar.gz: be224a555d90519241d32b8e2232fe357b7feca228cdd789a011d6ea76ef388bfee1528adcafeefb9a19058c0aab276ca5576b41192e844a439f730f76705af8
@@ -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.
@@ -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,19 +1,23 @@
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
2
  A gem providing convenient navigation of the [Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar).
3
+ Originally developed for [Simulmedia](https://simulmedia.com).
3
4
 
4
5
  ## Installation
5
6
  Add this line to your application's Gemfile:
7
+
6
8
  ```ruby
7
9
  # update with the version of your choice
8
10
  gem 'timeboss'
9
11
  ```
10
12
 
11
13
  And then execute:
14
+
12
15
  ```bash
13
16
  $ bundle install
14
17
  ```
15
18
 
16
19
  Or install it yourself as:
20
+
17
21
  ```bash
18
22
  $ gem install timeboss
19
23
  ```
@@ -22,6 +26,7 @@ $ gem install timeboss
22
26
  Supports `year`, `half`, `quarter`, `month`, `week`, and `day`.
23
27
 
24
28
  Prepare your calendar for use:
29
+
25
30
  ```ruby
26
31
  require 'timeboss/calendars/broadcast'
27
32
 
@@ -30,6 +35,7 @@ calendar = TimeBoss::Calendars::Broadcast.new
30
35
  ```
31
36
 
32
37
  You can ask simple questions of the calendar:
38
+
33
39
  ```ruby
34
40
  period = calendar.parse('2019Q4') # or '2018', or '2019-12-21', or '2020W32', or '2020M3W2'
35
41
  # => #<TimeBoss::Calendar::Quarter:0x007f82d50e2478>
@@ -61,6 +67,7 @@ calendar.weeks_hence(3).name # run in 2020W29
61
67
  ```
62
68
 
63
69
  The resulting periods can be formatted a variety of (parsable) ways:
70
+
64
71
  ```ruby
65
72
  entry = calendar.parse('2020M24')
66
73
  entry.format
@@ -72,9 +79,11 @@ entry.format(:quarter)
72
79
  entry.format(:quarter, :month)
73
80
  # => "2020Q2M3W2"
74
81
  ```
82
+
75
83
  _Note: all parsable descriptors should be ordered by chronological specificity (from least to most)_
76
84
 
77
85
  Each type of period can give you information about its constituent periods:
86
+
78
87
  ```ruby
79
88
  calendar.this_month.weeks.map(&:to_s)
80
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"]
@@ -90,6 +99,7 @@ calendar.parse('2020Q1').months.map(&:name)
90
99
  ```
91
100
 
92
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
+
93
103
  ```ruby
94
104
  calendar.parse('Q3').years_ago(5).title
95
105
  # => "Q3 2015"
@@ -108,6 +118,7 @@ calendar.this_week.next_year.to_s # run 2020W29
108
118
  ```
109
119
 
110
120
  Complicated range expressions can be parsed using the `..` range operator, or evaluated with `thru`:
121
+
111
122
  ```ruby
112
123
  calendar.parse('2020M1 .. 2020M2').weeks.map(&:title)
113
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"]
@@ -125,6 +136,7 @@ The examples above are just samples. Try different periods, operators, etc.
125
136
  ### Shell
126
137
  To open an IRB shell for the broadcast calendar, use the `tbsh` executable, or the `timeboss:calendars:broadcast:shell` rake task.
127
138
  You will find yourself in the context of an instantiated `TimeBoss::Calendars::Broadcast` object:
139
+
128
140
  ```bash
129
141
  $ tbsh
130
142
  2.4.1 :001 > next_quarter
@@ -190,17 +202,21 @@ end
190
202
  ```
191
203
 
192
204
  With the new calendar implemented, it can be accessed in one of 2 ways:
205
+
193
206
  - via traditional instantiation:
194
- ```ruby
195
- calendar = MyCalendars::AugustFiscal.new
196
- calendar.this_year
197
- ```
207
+
208
+ ```ruby
209
+ calendar = MyCalendars::AugustFiscal.new
210
+ calendar.this_year
211
+ ```
212
+
198
213
  - via `TimeBoss::Calendars`:
199
- ```ruby
200
- require 'timeboss/calendars'
201
- calendar = TimeBoss::Calendars[:august_fiscal]
202
- calendar.this_year
203
- ```
214
+
215
+ ```ruby
216
+ require 'timeboss/calendars'
217
+ calendar = TimeBoss::Calendars[:august_fiscal]
218
+ calendar.this_year
219
+ ```
204
220
 
205
221
  ## TODO
206
222
  - [ ] Add comprehensive documentation
@@ -24,11 +24,13 @@ module TimeBoss
24
24
  @_index ||= (start_date - calendar.year_for(start_date).start_date).to_i + 1
25
25
  end
26
26
 
27
- def previous
27
+ private
28
+
29
+ def down
28
30
  self.class.new(calendar, start_date - 1.day)
29
31
  end
30
32
 
31
- def next
33
+ def up
32
34
  self.class.new(calendar, start_date + 1.day)
33
35
  end
34
36
  end
@@ -13,22 +13,6 @@ module TimeBoss
13
13
  @index = index
14
14
  end
15
15
 
16
- def next
17
- if index == max_index
18
- calendar.send(self.class.type, year_index + 1, 1)
19
- else
20
- calendar.send(self.class.type, year_index, index + 1)
21
- end
22
- end
23
-
24
- def previous
25
- if index == 1
26
- calendar.send(self.class.type, year_index - 1, max_index)
27
- else
28
- calendar.send(self.class.type, year_index, index - 1)
29
- end
30
- end
31
-
32
16
  def to_s
33
17
  "#{name}: #{start_date} thru #{end_date}"
34
18
  end
@@ -45,6 +29,22 @@ module TimeBoss
45
29
  def max_index
46
30
  12 / self.class::NUM_MONTHS
47
31
  end
32
+
33
+ def up
34
+ if index == max_index
35
+ calendar.send(self.class.type, year_index + 1, 1)
36
+ else
37
+ calendar.send(self.class.type, year_index, index + 1)
38
+ end
39
+ end
40
+
41
+ def down
42
+ if index == 1
43
+ calendar.send(self.class.type, year_index - 1, max_index)
44
+ else
45
+ calendar.send(self.class.type, year_index, index - 1)
46
+ end
47
+ end
48
48
  end
49
49
  end
50
50
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ module TimeBoss
3
+ class Calendar
4
+ module Support
5
+ module Navigable
6
+ def previous(quantity = nil)
7
+ return down if quantity.nil?
8
+ gather(:previous, quantity).reverse
9
+ end
10
+
11
+ def next(quantity = nil)
12
+ return up if quantity.nil?
13
+ gather(:next, quantity)
14
+ end
15
+
16
+ def ago(quantity)
17
+ previous(quantity + 1).first
18
+ end
19
+
20
+ def hence(quantity)
21
+ self.next(quantity + 1).last
22
+ end
23
+
24
+ def until(end_date)
25
+ entry = self
26
+ [entry].tap do |entries|
27
+ until entry.end_date >= end_date
28
+ entry = entry.next
29
+ entries << entry
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def gather(navigator, quantity)
37
+ [].tap do |entries|
38
+ entry = self
39
+ while quantity > 0
40
+ entries << entry
41
+ entry = entry.send(navigator)
42
+ quantity -= 1
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require_relative './navigable'
2
3
  require_relative './shiftable'
3
4
  require_relative './formatter'
4
5
 
@@ -6,6 +7,7 @@ module TimeBoss
6
7
  class Calendar
7
8
  module Support
8
9
  class Unit
10
+ include Navigable
9
11
  include Shiftable
10
12
  attr_reader :calendar, :start_date, :end_date
11
13
 
@@ -21,54 +21,12 @@ module TimeBoss
21
21
  end
22
22
  end
23
23
 
24
- %i[day week month quarter half year].each do |type|
25
- define_method("this_#{type}") { send("#{type}_for", Date.today) }
26
- define_method("last_#{type}") { send("this_#{type}").previous }
27
- define_method("next_#{type}") { send("this_#{type}").next }
28
-
29
- define_method "#{type.to_s.pluralize}_for" do |entry|
30
- first = send("#{type}_for", entry.start_date)
31
- constituents = [first]
32
- until first.end_date >= entry.end_date
33
- first = first.next
34
- constituents << first
35
- end
36
- constituents
37
- end
38
-
39
- define_method "#{type.to_s.pluralize}_back" do |quantity|
40
- windows = []
41
- window = send("this_#{type}")
42
- while quantity > 0
43
- windows << window.dup
44
- window = window.previous
45
- quantity -= 1
46
- end
47
- windows.reverse
48
- end
49
-
50
- define_method "#{type.to_s.pluralize}_ago" do |quantity|
51
- send("#{type.to_s.pluralize}_back", quantity + 1).first
52
- end
53
-
54
- define_method type.to_s.pluralize do |quantity|
55
- windows = []
56
- window = send("this_#{type}")
57
- while quantity > 0
58
- windows << window.dup
59
- window = window.next
60
- quantity -= 1
61
- end
62
- windows
63
- end
64
-
65
- define_method "#{type.to_s.pluralize}_hence" do |quantity|
66
- send(type.to_s.pluralize, quantity + 1).last
67
- end
24
+ def week(year_index, index)
25
+ year(year_index).weeks[index - 1]
68
26
  end
69
27
 
70
- %i[yesterday today tomorrow].each do |period|
71
- define_method(period) { Day.new(self, Date.send(period)) }
28
+ def week_for(date)
29
+ year_for(date).weeks.find { |w| w.to_range.include?(date) }
72
30
  end
73
31
 
74
32
  def day(year_index, index)
@@ -79,9 +37,26 @@ module TimeBoss
79
37
  Day.new(self, date)
80
38
  end
81
39
 
82
- def week_for(date)
83
- year_for(date).weeks.find { |w| w.to_range.include?(date) }
40
+ %i[day week month quarter half year].each do |type|
41
+ types = type.to_s.pluralize
42
+
43
+ define_method("this_#{type}") { send("#{type}_for", Date.today) }
44
+ define_method("last_#{type}") { send("this_#{type}").previous }
45
+ define_method("next_#{type}") { send("this_#{type}").next }
46
+
47
+ define_method("#{types}_for") { |p| send("#{type}_for", p.start_date).until(p.end_date) }
48
+
49
+ define_method("#{types}_back") { |q| send("this_#{type}").previous(q) }
50
+ define_method("#{types}_ago") { |q| send("this_#{type}").ago(q) }
51
+
52
+ define_method("#{types}_forward") { |q| send("this_#{type}").next(q) }
53
+ define_method("#{types}_hence") { |q| send("this_#{type}").hence(q) }
54
+ alias_method types.to_sym, "#{types}_forward".to_sym
84
55
  end
56
+
57
+ alias_method :yesterday, :last_day
58
+ alias_method :today, :this_day
59
+ alias_method :tomorrow, :next_day
85
60
  end
86
61
  end
87
62
  end
@@ -24,7 +24,9 @@ module TimeBoss
24
24
  "#{name}: #{start_date} thru #{end_date}"
25
25
  end
26
26
 
27
- def previous
27
+ private
28
+
29
+ def down
28
30
  if index == 1
29
31
  (calendar.year_for(start_date) - 1).weeks.last
30
32
  else
@@ -32,7 +34,7 @@ module TimeBoss
32
34
  end
33
35
  end
34
36
 
35
- def next
37
+ def up
36
38
  weeks = calendar.year_for(start_date).weeks
37
39
  if index == weeks.last.index
38
40
  self.class.new(calendar, year_index + 1, 1, start_date + 1.week, end_date + 1.week)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TimeBoss
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
@@ -2,6 +2,26 @@ module TimeBoss
2
2
  describe Calendars::Broadcast do
3
3
  let(:subject) { described_class.new }
4
4
 
5
+ context 'days' do
6
+ it 'can get today' do
7
+ day = subject.today
8
+ expect(day).to be_instance_of(TimeBoss::Calendar::Day)
9
+ expect(day.start_date).to eq Date.today
10
+ end
11
+
12
+ it 'can get yesterday' do
13
+ day = subject.yesterday
14
+ expect(day).to be_instance_of(TimeBoss::Calendar::Day)
15
+ expect(day.start_date).to eq Date.yesterday
16
+ end
17
+
18
+ it 'can get tomorrow' do
19
+ day = subject.tomorrow
20
+ expect(day).to be_instance_of(TimeBoss::Calendar::Day)
21
+ expect(day.start_date).to eq Date.tomorrow
22
+ end
23
+ end
24
+
5
25
  context 'quarters' do
6
26
  describe '#quarter' do
7
27
  it 'knows 2017Q2' 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.0.8
4
+ version: 0.0.9
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-17 00:00:00.000000000 Z
11
+ date: 2020-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,9 +116,12 @@ executables:
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
120
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
119
121
  - ".gitignore"
120
122
  - ".rspec"
121
123
  - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
122
125
  - Gemfile
123
126
  - LICENSE.txt
124
127
  - README.md
@@ -137,6 +140,7 @@ files:
137
140
  - lib/timeboss/calendar/support/formatter.rb
138
141
  - lib/timeboss/calendar/support/month_based.rb
139
142
  - lib/timeboss/calendar/support/month_basis.rb
143
+ - lib/timeboss/calendar/support/navigable.rb
140
144
  - lib/timeboss/calendar/support/shiftable.rb
141
145
  - lib/timeboss/calendar/support/unit.rb
142
146
  - lib/timeboss/calendar/waypoints.rb