timeboss 0.1.0 → 0.1.1

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -4
  3. data/lib/timeboss/calendar.rb +0 -1
  4. data/lib/timeboss/calendar/day.rb +0 -1
  5. data/lib/timeboss/calendar/half.rb +0 -1
  6. data/lib/timeboss/calendar/month.rb +0 -1
  7. data/lib/timeboss/calendar/parser.rb +0 -1
  8. data/lib/timeboss/calendar/period.rb +0 -1
  9. data/lib/timeboss/calendar/quarter.rb +0 -1
  10. data/lib/timeboss/calendar/support/formatter.rb +2 -2
  11. data/lib/timeboss/calendar/support/month_basis.rb +0 -2
  12. data/lib/timeboss/calendar/support/monthly_unit.rb +0 -2
  13. data/lib/timeboss/calendar/support/navigable.rb +0 -1
  14. data/lib/timeboss/calendar/support/shiftable.rb +218 -29
  15. data/lib/timeboss/calendar/support/translatable.rb +92 -0
  16. data/lib/timeboss/calendar/support/unit.rb +2 -1
  17. data/lib/timeboss/calendar/waypoints.rb +0 -1
  18. data/lib/timeboss/calendar/waypoints/absolute.rb +0 -1
  19. data/lib/timeboss/calendar/waypoints/relative.rb +0 -1
  20. data/lib/timeboss/calendar/week.rb +0 -1
  21. data/lib/timeboss/calendar/year.rb +0 -1
  22. data/lib/timeboss/calendars.rb +0 -1
  23. data/lib/timeboss/version.rb +1 -1
  24. metadata +4 -49
  25. data/doc/TimeBoss.html +0 -146
  26. data/doc/TimeBoss/Calendar.html +0 -137
  27. data/doc/TimeBoss/Calendar/Day.html +0 -594
  28. data/doc/TimeBoss/Calendar/Half.html +0 -396
  29. data/doc/TimeBoss/Calendar/Month.html +0 -396
  30. data/doc/TimeBoss/Calendar/Parser.html +0 -386
  31. data/doc/TimeBoss/Calendar/Period.html +0 -841
  32. data/doc/TimeBoss/Calendar/Quarter.html +0 -396
  33. data/doc/TimeBoss/Calendar/Support.html +0 -131
  34. data/doc/TimeBoss/Calendar/Support/Formatter.html +0 -459
  35. data/doc/TimeBoss/Calendar/Support/MonthBased.html +0 -591
  36. data/doc/TimeBoss/Calendar/Support/MonthBasis.html +0 -437
  37. data/doc/TimeBoss/Calendar/Support/MonthlyUnit.html +0 -591
  38. data/doc/TimeBoss/Calendar/Support/Navigable.html +0 -723
  39. data/doc/TimeBoss/Calendar/Support/Shiftable.html +0 -138
  40. data/doc/TimeBoss/Calendar/Support/Unit.html +0 -1299
  41. data/doc/TimeBoss/Calendar/Waypoints.html +0 -155
  42. data/doc/TimeBoss/Calendar/Waypoints/Absolute.html +0 -1378
  43. data/doc/TimeBoss/Calendar/Waypoints/Relative.html +0 -4308
  44. data/doc/TimeBoss/Calendar/Week.html +0 -671
  45. data/doc/TimeBoss/Calendar/Year.html +0 -319
  46. data/doc/TimeBoss/Calendars.html +0 -336
  47. data/doc/TimeBoss/Calendars/Broadcast.html +0 -221
  48. data/doc/TimeBoss/Calendars/Broadcast/Basis.html +0 -278
  49. data/doc/TimeBoss/Calendars/Entry.html +0 -399
  50. data/doc/TimeBoss/Support.html +0 -115
  51. data/doc/TimeBoss/Support/Shellable.html +0 -249
  52. data/doc/_index.html +0 -416
  53. data/doc/class_list.html +0 -51
  54. data/doc/css/common.css +0 -1
  55. data/doc/css/full_list.css +0 -58
  56. data/doc/css/style.css +0 -496
  57. data/doc/file.README.html +0 -299
  58. data/doc/file_list.html +0 -56
  59. data/doc/frames.html +0 -17
  60. data/doc/index.html +0 -299
  61. data/doc/js/app.js +0 -314
  62. data/doc/js/full_list.js +0 -216
  63. data/doc/js/jquery.js +0 -4
  64. data/doc/method_list.html +0 -1139
  65. data/doc/top-level-namespace.html +0 -110
  66. data/lib/timeboss/calendar/support.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ad33c552922fb61c6b798d0c32ab7b125d561b1d0aae10eae486317d65ed624
4
- data.tar.gz: 9744c0da3d9d10b28c3a23d6c384c48dd4b2cd8b2d910e97c362dcac9c9a3bf4
3
+ metadata.gz: b27f1fec825b8ddb084a029a0621d939bd2525a67f33879611dfc36f6a722d4c
4
+ data.tar.gz: 93fb0c6366dab6a4e577c1507d8cb99ddbb952ebfeea5ec67f134d1ba0c33c14
5
5
  SHA512:
6
- metadata.gz: 8d3a750e0901981ad30ec9bab9f3c155f13ea6689293ff5b46f574ae074ee79f712a2d5e3ba9f4dc0e10b492d4252a20b879f244d92afb1ce21417a2231530c1
7
- data.tar.gz: 8d3c3d6b5f6e4df76b69e78853758a12a347c9e65957d1ee03d55229e9f04c526ddbfc912bdc1a89407635e306b6207b06e5f8d008eed2cec260e59c0948ce6b
6
+ metadata.gz: dab7d412003da6fd0b753e49a46c8d877f15cf802997fa3ad172ad48b2fd571aeb9288572254bf8b4a9289f4eccdaef2f6cc1d88e4a0d0512beea946022fe7df
7
+ data.tar.gz: 197ae44718c8dca52c091d90ab6c0a80f0e45d3207b095ff8194801b06481f20efabb6612ba822270c682429da12b16c0e08c87b91ff7e0b72440dcf8b3573ee
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
- /*.gem
2
- /Gemfile.lock
3
- /.bundle
4
- /.yardoc
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ .yardoc
5
+ doc
@@ -7,7 +7,6 @@ require 'active_support/core_ext/numeric/time'
7
7
  require_relative './calendar/support/month_basis'
8
8
 
9
9
  module TimeBoss
10
- # A calendar is built upon a basis, and provides methods for period identification and navigation.
11
10
  class Calendar
12
11
  include Waypoints
13
12
 
@@ -3,7 +3,6 @@ require_relative './support/unit'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
6
- # Representation of a single day within a calendar.
7
6
  class Day < Support::Unit
8
7
  def initialize(calendar, start_date)
9
8
  super(calendar, start_date, start_date)
@@ -3,7 +3,6 @@ require_relative './support/monthly_unit'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
6
- # Representation of a 6-month period within a calendar.
7
6
  class Half < Support::MonthlyUnit
8
7
  NUM_MONTHS = 6
9
8
 
@@ -3,7 +3,6 @@ require_relative './support/monthly_unit'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
6
- # Representation of a single month within a calendar.
7
6
  class Month < Support::MonthlyUnit
8
7
  NUM_MONTHS = 1
9
8
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module TimeBoss
3
3
  class Calendar
4
- # The parser is responsible for the implementation of a calendar's identifier parsing abilities.
5
4
  class Parser
6
5
  RANGE_DELIMITER = '..'
7
6
  InvalidPeriodIdentifierError = Class.new(StandardError)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module TimeBoss
3
3
  class Calendar
4
- # A calendar period represents a range of units.
5
4
  class Period
6
5
  attr_reader :begin, :end
7
6
 
@@ -3,7 +3,6 @@ require_relative './support/monthly_unit'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
6
- # Representation of a 3-month period within a calendar.
7
6
  class Quarter < Support::MonthlyUnit
8
7
  NUM_MONTHS = 3
9
8
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require_relative './shiftable'
2
+ require_relative './translatable'
3
3
 
4
4
  module TimeBoss
5
5
  class Calendar
@@ -8,7 +8,7 @@ module TimeBoss
8
8
 
9
9
  # The formatter is responsible for the implementation of name formatting for a unit.
10
10
  class Formatter
11
- PERIODS = Shiftable::PERIODS.reverse.map(&:to_sym).drop(1)
11
+ PERIODS = Translatable::PERIODS.reverse.map(&:to_sym).drop(1)
12
12
  attr_reader :unit, :periods
13
13
 
14
14
  def initialize(unit, periods)
@@ -2,8 +2,6 @@ module TimeBoss
2
2
  class Calendar
3
3
  module Support
4
4
  # @abstract
5
- # Implementation of a month basis allows a custom calendar to be built.
6
- # A month basis must return a start/end date for a given year and month index.
7
5
  class MonthBasis
8
6
  attr_reader :year, :month
9
7
 
@@ -4,8 +4,6 @@ require_relative './unit'
4
4
  module TimeBoss
5
5
  class Calendar
6
6
  module Support
7
- # Units that are built off of month-granularities (months, quarters, etc).
8
- # Days and weeks are not built from these.
9
7
  class MonthlyUnit < Unit
10
8
  attr_reader :year_index, :index
11
9
 
@@ -2,7 +2,6 @@
2
2
  module TimeBoss
3
3
  class Calendar
4
4
  module Support
5
- # Provides navigational abilities for units within a calendar.
6
5
  module Navigable
7
6
  # @overload previous
8
7
  # Fetch the previous unit relative to this unit.
@@ -2,50 +2,239 @@
2
2
  module TimeBoss
3
3
  class Calendar
4
4
  module Support
5
- # Provides the ability to take a unit, and shift it into a different period, relative to today.
6
5
  module Shiftable
7
- PERIODS = %w[day week month quarter half year]
8
-
9
- PERIODS.each do |period|
6
+ Support::Translatable::PERIODS.each do |period|
10
7
  periods = period.pluralize
11
8
 
12
- define_method periods do
13
- calendar.send("#{periods}_for", self)
14
- end
15
-
16
- define_method period do
17
- entries = send(periods)
18
- return nil unless entries.length == 1
19
- entries.first
20
- end
21
-
22
- define_method "in_#{period}" do
9
+ define_method("in_#{period}") do
23
10
  base = send(periods)
24
11
  return unless base.length == 1
25
12
  base.first.send(self.class.type.to_s.pluralize).find_index { |p| p == self } + 1
26
13
  end
27
14
 
28
- define_method "#{periods}_ago" do |offset|
15
+ define_method("#{periods}_ago") do |offset|
29
16
  base_offset = send("in_#{period}") or return
30
17
  (calendar.send("this_#{period}") - offset).send(self.class.type.to_s.pluralize)[base_offset - 1]
31
18
  end
32
19
 
33
- define_method "last_#{period}" do
34
- send("#{periods}_ago", 1)
35
- end
20
+ define_method("#{periods}_ahead") { |o| send("#{periods}_ago", o * -1) }
36
21
 
37
- define_method "this_#{period}" do
38
- send("#{periods}_ago", 0)
39
- end
22
+ define_method("last_#{period}") { send("#{periods}_ago", 1) }
23
+ define_method("this_#{period}") { send("#{periods}_ago", 0) }
24
+ define_method("next_#{period}") { send("#{periods}_ahead", 1) }
25
+ end
40
26
 
41
- define_method "#{periods}_ahead" do |offset|
42
- send("#{periods}_ago", offset * -1)
43
- end
27
+ alias_method :yesterday, :last_day
28
+ alias_method :today, :this_day
29
+ alias_method :tomorrow, :next_day
44
30
 
45
- define_method "next_#{period}" do
46
- send("#{periods}_ahead", 1)
47
- end
48
- end
31
+ #
32
+ # i hate this
33
+ #
34
+
35
+ ### Days
36
+
37
+ # @!method in_day
38
+ # Get the index within the day that this unit falls in.
39
+ # Returns nil if no single day can be identified.
40
+ # @return [Integer, nil]
41
+
42
+ # @!method days_ago
43
+ # Get the index-relative day some number of days ago.
44
+ # Returns nil if no single day can be identified.
45
+ # @param offset [Integer] the number of days back to shift this period
46
+ # @return [Calendar::Day, nil]
47
+
48
+ # @!method days_ahead
49
+ # Get the index-relative day some number of days ahead.
50
+ # Returns nil if no single day can be identified.
51
+ # @param offset [Integer] the number of days forward to shift this period
52
+ # @return [Calendar::Day, nil]
53
+
54
+ # @!method last_day
55
+ # Get the index-relative day 1 day ago.
56
+ # Returns nil if no single day can be identified.
57
+ # @return [Calendar::Day, nil]
58
+
59
+ # @!method this_day
60
+ # Get the index-relative day for this day.
61
+ # Returns nil if no single day can be identified.
62
+ # @return [Calendar::Day, nil]
63
+
64
+ # @!method next_day
65
+ # Get the index-relative day 1 day forward.
66
+ # Returns nil if no single day can be identified.
67
+ # @return [Calendar::Day, nil]
68
+
69
+ ### Weeks
70
+
71
+ # @!method in_week
72
+ # Get the index within the week that this unit falls in.
73
+ # Returns nil if no single week can be identified.
74
+ # @return [Integer, nil]
75
+
76
+ # @!method weeks_ago
77
+ # Get the index-relative week some number of weeks ago.
78
+ # Returns nil if no single week can be identified.
79
+ # @param offset [Integer] the number of weeks back to shift this period
80
+ # @return [Calendar::Week, nil]
81
+
82
+ # @!method weeks_ahead
83
+ # Get the index-relative week some number of weeks ahead.
84
+ # Returns nil if no single week can be identified.
85
+ # @param offset [Integer] the number of weeks forward to shift this period
86
+ # @return [Calendar::Week, nil]
87
+
88
+ # @!method last_week
89
+ # Get the index-relative week 1 week ago.
90
+ # Returns nil if no single week can be identified.
91
+ # @return [Calendar::Week, nil]
92
+
93
+ # @!method this_week
94
+ # Get the index-relative week for this week.
95
+ # Returns nil if no single week can be identified.
96
+ # @return [Calendar::Week, nil]
97
+
98
+ # @!method next_week
99
+ # Get the index-relative week 1 week forward.
100
+ # Returns nil if no single week can be identified.
101
+ # @return [Calendar::Week, nil]
102
+
103
+ ### Months
104
+
105
+ # @!method in_month
106
+ # Get the index within the month that this unit falls in.
107
+ # Returns nil if no single month can be identified.
108
+ # @return [Integer, nil]
109
+
110
+ # @!method months_ago
111
+ # Get the index-relative month some number of months ago.
112
+ # Returns nil if no single month can be identified.
113
+ # @param offset [Integer] the number of months back to shift this period
114
+ # @return [Calendar::Month, nil]
115
+
116
+ # @!method months_ahead
117
+ # Get the index-relative month some number of months ahead.
118
+ # Returns nil if no single month can be identified.
119
+ # @param offset [Integer] the number of months forward to shift this period
120
+ # @return [Calendar::Month, nil]
121
+
122
+ # @!method last_month
123
+ # Get the index-relative month 1 month ago.
124
+ # Returns nil if no single month can be identified.
125
+ # @return [Calendar::Month, nil]
126
+
127
+ # @!method this_month
128
+ # Get the index-relative month for this month.
129
+ # Returns nil if no single month can be identified.
130
+ # @return [Calendar::Month, nil]
131
+
132
+ # @!method next_month
133
+ # Get the index-relative month 1 month forward.
134
+ # Returns nil if no single month can be identified.
135
+ # @return [Calendar::Month, nil]
136
+
137
+ ### Quarters
138
+
139
+ # @!method in_quarter
140
+ # Get the index within the quarter that this unit falls in.
141
+ # Returns nil if no single quarter can be identified.
142
+ # @return [Integer, nil]
143
+
144
+ # @!method quarters_ago
145
+ # Get the index-relative quarter some number of quarters ago.
146
+ # Returns nil if no single quarter can be identified.
147
+ # @param offset [Integer] the number of quarters back to shift this period
148
+ # @return [Calendar::Quarter, nil]
149
+
150
+ # @!method quarters_ahead
151
+ # Get the index-relative quarter some number of quarters ahead.
152
+ # Returns nil if no single quarter can be identified.
153
+ # @param offset [Integer] the number of quarters forward to shift this period
154
+ # @return [Calendar::Quarter, nil]
155
+
156
+ # @!method last_quarter
157
+ # Get the index-relative quarter 1 quarter ago.
158
+ # Returns nil if no single quarter can be identified.
159
+ # @return [Calendar::Quarter, nil]
160
+
161
+ # @!method this_quarter
162
+ # Get the index-relative quarter for this quarter.
163
+ # Returns nil if no single quarter can be identified.
164
+ # @return [Calendar::Quarter, nil]
165
+
166
+ # @!method next_quarter
167
+ # Get the index-relative quarter 1 quarter forward.
168
+ # Returns nil if no single quarter can be identified.
169
+ # @return [Calendar::Quarter, nil]
170
+
171
+ ### Halves
172
+
173
+ # @!method in_half
174
+ # Get the index within the half that this unit falls in.
175
+ # Returns nil if no single half can be identified.
176
+ # @return [Integer, nil]
177
+
178
+ # @!method halves_ago
179
+ # Get the index-relative half some number of halves ago.
180
+ # Returns nil if no single half can be identified.
181
+ # @param offset [Integer] the number of halves back to shift this period
182
+ # @return [Calendar::Half, nil]
183
+
184
+ # @!method halves_ahead
185
+ # Get the index-relative half some number of halves ahead.
186
+ # Returns nil if no single half can be identified.
187
+ # @param offset [Integer] the number of halves forward to shift this period
188
+ # @return [Calendar::Half, nil]
189
+
190
+ # @!method last_half
191
+ # Get the index-relative half 1 half ago.
192
+ # Returns nil if no single half can be identified.
193
+ # @return [Calendar::Half, nil]
194
+
195
+ # @!method this_half
196
+ # Get the index-relative half for this half.
197
+ # Returns nil if no single half can be identified.
198
+ # @return [Calendar::Half, nil]
199
+
200
+ # @!method next_half
201
+ # Get the index-relative half 1 half forward.
202
+ # Returns nil if no single half can be identified.
203
+ # @return [Calendar::Half, nil]
204
+
205
+ ### Years
206
+
207
+ # @!method in_year
208
+ # Get the index within the year that this unit falls in.
209
+ # Returns nil if no single year can be identified.
210
+ # @return [Integer, nil]
211
+
212
+ # @!method years_ago
213
+ # Get the index-relative year some number of years ago.
214
+ # Returns nil if no single year can be identified.
215
+ # @param offset [Integer] the number of years back to shift this period
216
+ # @return [Calendar::Year, nil]
217
+
218
+ # @!method years_ahead
219
+ # Get the index-relative year some number of years ahead.
220
+ # Returns nil if no single year can be identified.
221
+ # @param offset [Integer] the number of years forward to shift this period
222
+ # @return [Calendar::Year, nil]
223
+
224
+ # @!method last_year
225
+ # Get the index-relative year 1 year ago.
226
+ # Returns nil if no single year can be identified.
227
+ # @return [Calendar::Year, nil]
228
+
229
+ # @!method this_year
230
+ # Get the index-relative year for this year.
231
+ # Returns nil if no single year can be identified.
232
+ # @return [Calendar::Year, nil]
233
+
234
+ # @!method next_year
235
+ # Get the index-relative year 1 year forward.
236
+ # Returns nil if no single year can be identified.
237
+ # @return [Calendar::Year, nil]
49
238
  end
50
239
  end
51
240
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+ module TimeBoss
3
+ class Calendar
4
+ module Support
5
+ module Translatable
6
+ PERIODS = %w[day week month quarter half year]
7
+
8
+ PERIODS.each do |period|
9
+ periods = period.pluralize
10
+
11
+ define_method(periods) { calendar.send("#{periods}_for", self) }
12
+
13
+ define_method(period) do
14
+ entries = send(periods)
15
+ return nil unless entries.length == 1
16
+ entries.first
17
+ end
18
+ end
19
+
20
+ #
21
+ # i hate this
22
+ #
23
+
24
+ ### Days
25
+
26
+ # @!method days
27
+ # Get a list of days that fall within this unit.
28
+ # @return [Array<Calendar::Day>]
29
+
30
+ # @!method day
31
+ # Get the day this unit represents.
32
+ # Returns nil if no single day can be identified.
33
+ # @return [Array<Calendar::Day>, nil]
34
+
35
+ ### Weeks
36
+
37
+ # @!method weeks
38
+ # Get a list of weeks that fall within this unit.
39
+ # @return [Array<Calendar::Week>]
40
+
41
+ # @!method week
42
+ # Get the week this unit represents.
43
+ # Returns nil if no single week can be identified.
44
+ # @return [Array<Calendar::Week>, nil]
45
+
46
+ ### Months
47
+
48
+ # @!method months
49
+ # Get a list of months that fall within this unit.
50
+ # @return [Array<Calendar::Month>]
51
+
52
+ # @!method month
53
+ # Get the month this unit represents.
54
+ # Returns nil if no single month can be identified.
55
+ # @return [Array<Calendar::Month>, nil]
56
+
57
+ ### Quarters
58
+
59
+ # @!method quarters
60
+ # Get a list of quarters that fall within this unit.
61
+ # @return [Array<Calendar::Quarter>]
62
+
63
+ # @!method quarter
64
+ # Get the quarter this unit represents.
65
+ # Returns nil if no single quarter can be identified.
66
+ # @return [Array<Calendar::Quarter>, nil]
67
+
68
+ ### Halves
69
+
70
+ # @!method halves
71
+ # Get a list of halves that fall within this unit.
72
+ # @return [Array<Calendar::Half>]
73
+
74
+ # @!method half
75
+ # Get the half this unit represents.
76
+ # Returns nil if no single half can be identified.
77
+ # @return [Array<Calendar::Half>, nil]
78
+
79
+ ### Years
80
+
81
+ # @!method years
82
+ # Get a list of years that fall within this unit.
83
+ # @return [Array<Calendar::Year>]
84
+
85
+ # @!method year
86
+ # Get the year this unit represents.
87
+ # Returns nil if no single year can be identified.
88
+ # @return [Array<Calendar::Year>, nil]
89
+ end
90
+ end
91
+ end
92
+ end