timeboss 0.0.5 → 0.0.10

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
- SHA1:
3
- metadata.gz: 5bd79ad6e3e02088a3dc23390a8aef1a37d2db8a
4
- data.tar.gz: 43e17929b3ffc20b7372282db1ca9024e87e11e3
2
+ SHA256:
3
+ metadata.gz: a46b4d08fd0e17154dbb9f2f806d74e3e0dd83ad2a6dff04102dd5142a975809
4
+ data.tar.gz: e231795ad178299e99475a03f7fc589d234373ce672f525653b9e67c209d00cc
5
5
  SHA512:
6
- metadata.gz: d72e587075701c343742b094537502127206ef2bc8beac51759d5e05bf35eb8306b1cea2161d3de76ed187a85cf04166e91273249ca399a44babeca35f4c17fd
7
- data.tar.gz: 37660d7992674849d783c35c662bf6c1fa921363a25c7a95afbdb1855d94583d3d469e8374ab67b2a6edeb8d8c8ef0e11e509a1cb46e6da27a40f07ee66d8cf5
6
+ metadata.gz: b4a01cd350e3df24190b5818e0cc71ea09b15e57ae73db9620e812b138b9badcb8acd8fb5fa33a35c52049e7893e37cf7a3beed40c8eebbbfddd46158d0ff72f
7
+ data.tar.gz: 493dd68afa5bd7df4b49c36881946ef869844f538a791780da86a966988be349debd9077a35cb0f834a20b5f0920088da2547cac33de1ec7618783d5f8f69b74
@@ -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,2 +1,3 @@
1
1
  /*.gem
2
2
  /Gemfile.lock
3
+ /.bundle
@@ -8,6 +8,9 @@ script:
8
8
  deploy:
9
9
  provider: rubygems
10
10
  api_key:
11
- secure: LKpYdRJImFZgpZ8NP5jah0pWUUwlmrXIW+dCfyFitm4Xf91XkZ3n4/g1WaUoZwmb/9FAian7PR/3XPuiNSEitr3J8DdbJMH9A/CG3VSyIgj/NE9w5Zl/mC6Pz8F0Ry7iSQ3kjhiW74927vRxc6VenHkm/oaBOwz3NfZQCoIEo27rDW1Xu+K4RviPL76k53Pm06C3xupibQ2m2+OKqwW8QlPCfcN1Q4Vkv/gokXjxGlxBYxxvEfZzCc3ul6TZTWeJgkSsfha6/MjHUj2q40sY+m4MMOrgdWGqau9xayJSQuDdP8c0C6hSyL2arHwbPDSO/4hsm0/h0Alfwrmm4sQmPcI2gVowL7yM44vTtTnuigRKhOFhgaNJH+mNTCGtAxH9Ke5Vx0ZjRKpWAXeE1Js1WARNX5gNj5jhZeyeQn5USV/YLJSqiB188Y0lnt3qdLc7h5FJlXWGgKf3+EPnnPupLaSkL9VWdMCVcP1hlp2CUhJo7dBKANzPiUP+sAsSuA3Ez681OOXPjRTfXFhfBSCd7XBnkvw/iZQeIiiZNbh/3CTKQ0tkJIwnnLR4qKsty3KZHH2cqxYfQkaSjmKDeHymQywWqPO9rUL6oxUz2chkLeiv9iEk/t8pTp+RBRx2K1fVB7/tZ1Ys+eGZBdS1lIrRmvvcVE0g6mAfcwhhyJHuPsk=
11
+ secure: jUWa2Jx0HRVv7Dl0zYPTskHQ+RJGy2TUcBWOjyFbBUbeDKiRh8J/NnbMuCOvmL94htSaFk5lcs6k74Itu6jW12+KyT98OAnOardFPFuI0cHHhIMEhF6ms8EhyOCZ0vvR9zav11gfNzyF716qO09DQSDuoKWWNdhrYj8a5paLdbHuRqQiw3YUmnjVQ/v9SPYaZ7ziXC4X4tBxQhK2ujNsNfztSVrpYb6pnsXnt+hFQOnskzi0+er4854iymykeyNVgB71KgivrE3T55ZTXPPglshsZQE7M7FlYA5L3bwzR7SlA202yFYHB3hUN3obwO3BjO4OiAdKQnSosBHaXI13ZvCOz02AfEJhwoxkBXw1/2CvSQ12QQPVgqkpxWY03h+URk+gGHCV+JaqZPCV9excmVWg/IOQou0IJ6h84VFViyVc2aFVN2AIdoaG3NsppbV3j4VuLG6J2VVpNmUzN3pGgi5YSjVq9Hp+huXZFfWpnUgAxc680hKgcFajE3JNANG+NbNEeoDmITvZyV5kvJklgUKPsl2wNk+wY/GGrSBgNOVlyXqTWLZb/8Z/cSrN5DEc6D5BIS/SG95wlCRT8jUqbyEPjT+H77TH2ySfwWZzblLqbIxaLiZr3hX16oMdUx7Cya5LKLFgQBpU6cFUxvZX7SqHwjk1vnuG592Kxd9GkX4=
12
+ gem: timeboss
12
13
  on:
13
14
  tags: true
15
+ repo: kevinstuffandthings/timeboss
16
+ skip_cleanup: 'true'
@@ -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,21 +1,23 @@
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
- gem 'timeboss', '0.0.1', git: "https://github.com/kevinstuffandthings/timeboss.git"
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
  ```
@@ -24,6 +26,7 @@ $ gem install timeboss
24
26
  Supports `year`, `half`, `quarter`, `month`, `week`, and `day`.
25
27
 
26
28
  Prepare your calendar for use:
29
+
27
30
  ```ruby
28
31
  require 'timeboss/calendars/broadcast'
29
32
 
@@ -32,6 +35,7 @@ calendar = TimeBoss::Calendars::Broadcast.new
32
35
  ```
33
36
 
34
37
  You can ask simple questions of the calendar:
38
+
35
39
  ```ruby
36
40
  period = calendar.parse('2019Q4') # or '2018', or '2019-12-21', or '2020W32', or '2020M3W2'
37
41
  # => #<TimeBoss::Calendar::Quarter:0x007f82d50e2478>
@@ -63,6 +67,7 @@ calendar.weeks_hence(3).name # run in 2020W29
63
67
  ```
64
68
 
65
69
  The resulting periods can be formatted a variety of (parsable) ways:
70
+
66
71
  ```ruby
67
72
  entry = calendar.parse('2020M24')
68
73
  entry.format
@@ -75,7 +80,10 @@ entry.format(:quarter, :month)
75
80
  # => "2020Q2M3W2"
76
81
  ```
77
82
 
83
+ _Note: all parsable descriptors should be ordered by chronological specificity (from least to most)_
84
+
78
85
  Each type of period can give you information about its constituent periods:
86
+
79
87
  ```ruby
80
88
  calendar.this_month.weeks.map(&:to_s)
81
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"]
@@ -91,6 +99,7 @@ calendar.parse('2020Q1').months.map(&:name)
91
99
  ```
92
100
 
93
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
+
94
103
  ```ruby
95
104
  calendar.parse('Q3').years_ago(5).title
96
105
  # => "Q3 2015"
@@ -109,6 +118,7 @@ calendar.this_week.next_year.to_s # run 2020W29
109
118
  ```
110
119
 
111
120
  Complicated range expressions can be parsed using the `..` range operator, or evaluated with `thru`:
121
+
112
122
  ```ruby
113
123
  calendar.parse('2020M1 .. 2020M2').weeks.map(&:title)
114
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"]
@@ -124,10 +134,11 @@ period = calendar.parse('2020W3..2020Q1')
124
134
  The examples above are just samples. Try different periods, operators, etc.
125
135
 
126
136
  ### Shell
127
- 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.
128
138
  You will find yourself in the context of an instantiated `TimeBoss::Calendars::Broadcast` object:
139
+
129
140
  ```bash
130
- $ rake timeboss:calendars:broadcast:shell
141
+ $ tbsh
131
142
  2.4.1 :001 > next_quarter
132
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)>>
133
144
  2.4.1 :002 > last_year
@@ -191,17 +202,21 @@ end
191
202
  ```
192
203
 
193
204
  With the new calendar implemented, it can be accessed in one of 2 ways:
205
+
194
206
  - via traditional instantiation:
195
- ```ruby
196
- calendar = MyCalendars::AugustFiscal.new
197
- calendar.this_year
198
- ```
207
+
208
+ ```ruby
209
+ calendar = MyCalendars::AugustFiscal.new
210
+ calendar.this_year
211
+ ```
212
+
199
213
  - via `TimeBoss::Calendars`:
200
- ```ruby
201
- require 'timeboss/calendars'
202
- calendar = TimeBoss::Calendars[:august_fiscal]
203
- calendar.this_year
204
- ```
214
+
215
+ ```ruby
216
+ require 'timeboss/calendars'
217
+ calendar = TimeBoss::Calendars[:august_fiscal]
218
+ calendar.this_year
219
+ ```
205
220
 
206
221
  ## TODO
207
- - [ ] 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'
@@ -11,6 +11,14 @@ module TimeBoss
11
11
  include Waypoints
12
12
  delegate :parse, to: :parser
13
13
 
14
+ def name
15
+ self.class.to_s.demodulize.underscore
16
+ end
17
+
18
+ def title
19
+ name.titleize
20
+ end
21
+
14
22
  protected
15
23
 
16
24
  attr_reader :basis
@@ -21,14 +21,20 @@ module TimeBoss
21
21
  end
22
22
 
23
23
  def index
24
- @_index ||= (start_date - calendar.year_for(start_date).start_date).to_i + 1
24
+ @_index ||= (start_date - year.start_date).to_i + 1
25
25
  end
26
26
 
27
- def previous
27
+ def year_index
28
+ @_year_index ||= year.year_index
29
+ end
30
+
31
+ private
32
+
33
+ def down
28
34
  self.class.new(calendar, start_date - 1.day)
29
35
  end
30
36
 
31
- def next
37
+ def up
32
38
  self.class.new(calendar, start_date + 1.day)
33
39
  end
34
40
  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
@@ -36,7 +20,7 @@ module TimeBoss
36
20
  def weeks
37
21
  base = calendar.year(year_index)
38
22
  num_weeks = (((base.end_date - base.start_date) + 1) / 7.0).to_i
39
- num_weeks.times.map { |i| Week.new(calendar, year_index, i + 1, base.start_date + (i * 7).days, base.start_date + ((i * 7) + 6).days) }
23
+ num_weeks.times.map { |i| Week.new(calendar, base.start_date + (i * 7).days, base.start_date + ((i * 7) + 6).days) }
40
24
  .select { |w| w.start_date.between?(start_date, end_date) }
41
25
  end
42
26
 
@@ -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
@@ -4,12 +4,8 @@ require_relative './support/unit'
4
4
  module TimeBoss
5
5
  class Calendar
6
6
  class Week < Support::Unit
7
- attr_reader :year_index, :index
8
-
9
- def initialize(calendar, year_index, index, start_date, end_date)
7
+ def initialize(calendar, start_date, end_date)
10
8
  super(calendar, start_date, end_date)
11
- @year_index = year_index
12
- @index = index
13
9
  end
14
10
 
15
11
  def name
@@ -24,21 +20,22 @@ module TimeBoss
24
20
  "#{name}: #{start_date} thru #{end_date}"
25
21
  end
26
22
 
27
- def previous
28
- if index == 1
29
- (calendar.year_for(start_date) - 1).weeks.last
30
- else
31
- self.class.new(calendar, year_index, index - 1, start_date - 1.week, end_date - 1.week)
32
- end
23
+ def index
24
+ @_index ||= (((start_date - year.start_date) + 1) / 7.0).to_i + 1
25
+ end
26
+
27
+ def year_index
28
+ @_year_index ||= year.year_index
29
+ end
30
+
31
+ private
32
+
33
+ def down
34
+ self.class.new(calendar, start_date - 1.week, end_date - 1.week)
33
35
  end
34
36
 
35
- def next
36
- weeks = calendar.year_for(start_date).weeks
37
- if index == weeks.last.index
38
- self.class.new(calendar, year_index + 1, 1, start_date + 1.week, end_date + 1.week)
39
- else
40
- weeks[index]
41
- end
37
+ def up
38
+ self.class.new(calendar, start_date + 1.week, end_date + 1.week)
42
39
  end
43
40
  end
44
41
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require 'active_support/core_ext/class/subclasses'
3
- require './lib/timeboss/calendar'
4
- Dir['./lib/timeboss/calendars/*.rb'].each { |f| require f }
3
+ require_relative 'calendar'
4
+
5
+ Dir[File.expand_path('../calendars/*.rb', __FILE__)].each { |f| require f }
5
6
 
6
7
  module TimeBoss
7
8
  module Calendars
@@ -16,7 +17,7 @@ module TimeBoss
16
17
  end
17
18
 
18
19
  def [](name)
19
- find { |e| e.name == name.to_sym }&.calendar
20
+ find { |e| e.name == name&.to_sym }&.calendar
20
21
  end
21
22
 
22
23
  private
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TimeBoss
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.10"
4
4
  end
@@ -24,7 +24,7 @@ module TimeBoss
24
24
  end
25
25
 
26
26
  describe '#index' do
27
- before(:each) { allow(calendar).to receive(:year_for).with(start_date).and_return double(start_date: start_date - 3) }
27
+ before(:each) { allow(subject).to receive(:year).and_return double(start_date: start_date - 3) }
28
28
 
29
29
  it 'gets its index within the year' do
30
30
  expect(subject.index).to eq 4
@@ -32,7 +32,17 @@ module TimeBoss
32
32
  it 'can get the relevant weeks for the period' do
33
33
  result = subject.weeks
34
34
  result.each { |w| expect(w).to be_instance_of TimeBoss::Calendar::Week }
35
- expect(result.map(&:name)).to eq %w[2018W26 2018W27 2018W28 2018W29 2018W30 2018W31 2018W32 2018W33 2018W34]
35
+ expect(result.map { |w| w.start_date.to_s }).to eq [
36
+ '2018-06-25',
37
+ '2018-07-02',
38
+ '2018-07-09',
39
+ '2018-07-16',
40
+ '2018-07-23',
41
+ '2018-07-30',
42
+ '2018-08-06',
43
+ '2018-08-13',
44
+ '2018-08-20'
45
+ ]
36
46
  end
37
47
  end
38
48
 
@@ -4,7 +4,7 @@ module TimeBoss
4
4
  let(:calendar) { instance_double(TimeBoss::Calendar) }
5
5
  let(:start_date) { Date.parse('2048-04-06') }
6
6
  let(:end_date) { Date.parse('2048-04-12') }
7
- let(:subject) { described_class.new(calendar, 2048, 15, start_date, end_date) }
7
+ let(:subject) { described_class.new(calendar, start_date, end_date) }
8
8
 
9
9
  it 'knows its stuff' do
10
10
  expect(subject.start_date).to eq start_date
@@ -12,18 +12,10 @@ module TimeBoss
12
12
  expect(subject.to_range).to eq start_date..end_date
13
13
  end
14
14
 
15
- it 'knows its name' do
16
- expect(subject.name).to eq '2048W15'
17
- end
18
-
19
15
  it 'knows its title' do
20
16
  expect(subject.title).to eq "Week of April 6, 2048"
21
17
  end
22
18
 
23
- it 'can stringify itself' do
24
- expect(subject.to_s).to include(subject.name, start_date.to_s, end_date.to_s)
25
- end
26
-
27
19
  describe '#current?' do
28
20
  it 'knows when it is' do
29
21
  allow(Date).to receive(:today).and_return start_date
@@ -46,13 +38,13 @@ module TimeBoss
46
38
  end
47
39
 
48
40
  it 'can wrap to the previous 52-week year' do
49
- result = described_class.new(calendar, 2022, 1, Date.parse('2021-12-27'), Date.parse('2022-01-02')).previous
41
+ result = described_class.new(calendar, Date.parse('2021-12-27'), Date.parse('2022-01-02')).previous
50
42
  expect(result).to be_a described_class
51
43
  expect(result.to_s).to eq "2021W52: 2021-12-20 thru 2021-12-26"
52
44
  end
53
45
 
54
46
  it 'can wrap to the previous 53-week year' do
55
- result = described_class.new(calendar, 2024, 1, Date.parse('2024-01-01'), Date.parse('2024-01-07')).previous
47
+ result = described_class.new(calendar, Date.parse('2024-01-01'), Date.parse('2024-01-07')).previous
56
48
  expect(result).to be_a described_class
57
49
  expect(result.to_s).to eq "2023W53: 2023-12-25 thru 2023-12-31"
58
50
  end
@@ -66,13 +58,13 @@ module TimeBoss
66
58
  end
67
59
 
68
60
  it 'can wrap from week 52 to the next year' do
69
- result = described_class.new(calendar, 2021, 52, Date.parse('2021-12-20'), Date.parse('2021-12-26')).next
61
+ result = described_class.new(calendar, Date.parse('2021-12-20'), Date.parse('2021-12-26')).next
70
62
  expect(result).to be_a described_class
71
63
  expect(result.to_s).to eq "2022W1: 2021-12-27 thru 2022-01-02"
72
64
  end
73
65
 
74
66
  it 'can wrap from week 53 to the next year' do
75
- result = described_class.new(calendar, 2023, 53, Date.parse('2023-12-25'), Date.parse('2023-12-31')).next
67
+ result = described_class.new(calendar, Date.parse('2023-12-25'), Date.parse('2023-12-31')).next
76
68
  expect(result).to be_a described_class
77
69
  expect(result.to_s).to eq "2024W1: 2024-01-01 thru 2024-01-07"
78
70
  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
@@ -28,10 +28,16 @@ module TimeBoss
28
28
  c2 = described_class[:broadcast]
29
29
  expect(c1).to be_instance_of TimeBoss::Calendars::Broadcast
30
30
  expect(c1).to be c2
31
+
32
+ expect(c1.name).to eq 'broadcast'
33
+ expect(c1.title).to eq 'Broadcast'
31
34
  end
32
35
 
33
36
  it 'can return a new calendar' do
34
- expect(described_class[:my_test_calendar]).to be_instance_of MyTestCalendar
37
+ c1 = described_class[:my_test_calendar]
38
+ expect(c1).to be_instance_of MyTestCalendar
39
+ expect(c1.name).to eq 'my_test_calendar'
40
+ expect(c1.title).to eq 'My Test Calendar'
35
41
  end
36
42
 
37
43
  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.0.5
4
+ version: 0.0.10
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-16 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
@@ -111,17 +111,22 @@ dependencies:
111
111
  description: Broadcast Calendar navigation in Ruby made simple
112
112
  email:
113
113
  - kevinstuffandthings@gmail.com
114
- executables: []
114
+ executables:
115
+ - tbsh
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
119
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
120
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
118
121
  - ".gitignore"
119
122
  - ".rspec"
120
123
  - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
121
125
  - Gemfile
122
126
  - LICENSE.txt
123
127
  - README.md
124
128
  - Rakefile
129
+ - bin/tbsh
125
130
  - lib/tasks/calendars.rake
126
131
  - lib/tasks/timeboss.rake
127
132
  - lib/timeboss.rb
@@ -135,6 +140,7 @@ files:
135
140
  - lib/timeboss/calendar/support/formatter.rb
136
141
  - lib/timeboss/calendar/support/month_based.rb
137
142
  - lib/timeboss/calendar/support/month_basis.rb
143
+ - lib/timeboss/calendar/support/navigable.rb
138
144
  - lib/timeboss/calendar/support/shiftable.rb
139
145
  - lib/timeboss/calendar/support/unit.rb
140
146
  - lib/timeboss/calendar/waypoints.rb
@@ -173,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
179
  version: '0'
174
180
  requirements: []
175
181
  rubyforge_project:
176
- rubygems_version: 2.6.14
182
+ rubygems_version: 2.7.7
177
183
  signing_key:
178
184
  specification_version: 4
179
185
  summary: Broadcast Calendar navigation in Ruby made simple