weekling 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ ��(QD`��.6��M�P�Ɩ�8�&X`dxv���[orVɪ�{�,�NO�p)��]����N�+H������>�
2
+ ^��}��X�ϳ}�;͋i�喅�L��`�`�i���o���.���)3@b���m٪jG4�*��3�F�CaG֛��;CCrJ#.�Tk"I���7L{G�}����
@@ -0,0 +1,10 @@
1
+ # Project metadata
2
+ nbproject
3
+ .idea
4
+
5
+ doc
6
+ coverage
7
+ pkg
8
+ .yardoc
9
+ .rbx
10
+ *.rbc
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - rbx-19mode
5
+ - jruby-19mode
@@ -0,0 +1,5 @@
1
+ --protected
2
+ --no-private
3
+ -
4
+ HISTORY.md
5
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
4
+
5
+ This file is part of Weekling.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ source 'http://rubygems.org'
21
+
22
+ # Specify your gem's dependencies in weekling.gemspec
23
+ gemspec
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ weekling (1.0.0rc1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ coderay (1.0.5)
10
+ diff-lcs (1.1.3)
11
+ maruku (0.6.0)
12
+ syntax (>= 1.0.0)
13
+ method_source (0.7.0)
14
+ multi_json (1.0.4)
15
+ pry (0.9.8)
16
+ coderay (~> 1.0.5)
17
+ method_source (~> 0.7)
18
+ slop (>= 2.4.3, < 3)
19
+ pry (0.9.8-java)
20
+ coderay (~> 1.0.5)
21
+ method_source (~> 0.7)
22
+ slop (>= 2.4.3, < 3)
23
+ spoon (~> 0.0)
24
+ rake (0.9.2.2)
25
+ rspec (2.6.0)
26
+ rspec-core (~> 2.6.0)
27
+ rspec-expectations (~> 2.6.0)
28
+ rspec-mocks (~> 2.6.0)
29
+ rspec-core (2.6.4)
30
+ rspec-expectations (2.6.0)
31
+ diff-lcs (~> 1.1.2)
32
+ rspec-mocks (2.6.0)
33
+ simplecov (0.5.4)
34
+ multi_json (~> 1.0.3)
35
+ simplecov-html (~> 0.5.3)
36
+ simplecov-html (0.5.3)
37
+ slop (2.4.3)
38
+ spoon (0.0.1)
39
+ syntax (1.0.0)
40
+ yard (0.7.5)
41
+
42
+ PLATFORMS
43
+ java
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.0.21)
48
+ maruku (~> 0.6.0)
49
+ pry (~> 0.9.8)
50
+ rake (~> 0.9.2)
51
+ rspec (~> 2.6.0)
52
+ simplecov (~> 0.5.4)
53
+ weekling!
54
+ yard (~> 0.7.5)
@@ -0,0 +1,6 @@
1
+ 1.0.0 / 2012-02-24
2
+ ==================
3
+
4
+ * 1 major enhancement
5
+
6
+ * Birthday!
@@ -0,0 +1,15 @@
1
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
2
+
3
+ Weekling is licensed under the following ISC-style license:
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,397 @@
1
+ Weekling
2
+ ========
3
+
4
+ [![Build Status](https://secure.travis-ci.org/aef/weekling.png)](
5
+ https://secure.travis-ci.org/aef/weekling)
6
+
7
+ * [Documentation][1]
8
+ * [Project][2]
9
+
10
+ [1]: http://rdoc.info/projects/aef/weekling/
11
+ [2]: http://github.com/aef/weekling/
12
+
13
+ Description
14
+ -----------
15
+
16
+ Weekling is a Ruby library which provides class representations to make date
17
+ calculations using years, weeks and week-days much easier. Years, weeks and
18
+ week-days are interpreted as in ISO 8601.
19
+
20
+ Features / Problems
21
+ -------------------
22
+
23
+ This projects tries to conform to:
24
+
25
+ * [Semantic Versioning (2.0.0-rc.1)][5]
26
+ * [Ruby Packaging Standard (0.5-draft)][6]
27
+ * [Ruby Style Guide][7]
28
+ * [Gem Packaging: Best Practices][8]
29
+
30
+ [5]: http://semver.org/
31
+ [6]: http://chneukirchen.github.com/rps/
32
+ [7]: https://github.com/bbatsov/ruby-style-guide
33
+ [8]: http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices
34
+
35
+ Additional facts:
36
+
37
+ * Written purely in Ruby.
38
+ * Intended to be used with Ruby 1.9.2 or compatible.
39
+ * Extends core classes. This can be disabled through bare mode.
40
+
41
+ Synopsis
42
+ --------
43
+
44
+ This documentation defines the public interface of the library. Don't rely
45
+ on elements marked as private. Those should be hidden in the documentation
46
+ by default.
47
+
48
+ ### Loading
49
+
50
+ In most cases you want to load the library by the following command:
51
+
52
+ ~~~~~ ruby
53
+ require 'weekling'
54
+ ~~~~~
55
+
56
+ In a bundler Gemfile you should use the following:
57
+
58
+ ~~~~~ ruby
59
+ gem 'weekling'
60
+ ~~~~~
61
+
62
+ By default, Weekling extends the Date, DateTime and Time classes to allow their
63
+ objects to be castable to Week and Week::Day. Additionally the Aef namespace is
64
+ included into Object, so that you don't have to type the fully-qualified names
65
+ of the classes. Should you really don't want this, use the following:
66
+
67
+ ~~~~~ ruby
68
+ require 'weekling/bare'
69
+ ~~~~~
70
+
71
+ Or for bundler Gemfiles:
72
+
73
+ ~~~~~ ruby
74
+ gem 'weekling', require: 'weekling/bare'
75
+ ~~~~~
76
+
77
+ The following examples are written for those who use the normal mode. If you
78
+ use the bare mode, you need to add Aef::Weekling in front of every class name.
79
+
80
+ ### Years
81
+
82
+ A Year object is constructed either by a date-like or and integer-like object:
83
+
84
+ ~~~~~ ruby
85
+ year = Year.new(Time.new(2014, 3, 12))
86
+ # => #<Aef::Weekling::Year: 2014>
87
+
88
+ year = Year.new(2014)
89
+ # => #<Aef::Weekling::Year: 2014>
90
+ ~~~~~
91
+
92
+ To get an Integer or String representation simply use the following:
93
+
94
+ ~~~~~ ruby
95
+ year.to_i
96
+ # => 2014
97
+
98
+ year.to_s
99
+ # => "2014"
100
+ ~~~~~
101
+
102
+ The next or previous years can be accessed by the respective methods:
103
+
104
+ ~~~~~ ruby
105
+ year.next
106
+ # => #<Aef::Weekling::Year: 2015>
107
+
108
+ year.previous
109
+ # => #<Aef::Weekling::Year: 2013>
110
+ ~~~~~
111
+
112
+ You can also add or subtract amounts of years to get another year object:
113
+
114
+ ~~~~~ ruby
115
+ year + 5
116
+ # => #<Aef::Weekling::Year: 2019>
117
+
118
+ year - 7
119
+ # => #<Aef::Weekling::Year: 2007>
120
+ ~~~~~
121
+
122
+ The year is also able to tell you if it is even or odd:
123
+
124
+ ~~~~~ ruby
125
+ year.even?
126
+ # => true
127
+
128
+ year.odd?
129
+ # => false
130
+ ~~~~~
131
+
132
+ The year also knows how many weeks it has:
133
+
134
+ ~~~~~ ruby
135
+ year.week_count
136
+ # => 52
137
+ ~~~~~
138
+
139
+ Or if it is a leap year:
140
+
141
+ ~~~~~ ruby
142
+ year.leap?
143
+ # => false
144
+ ~~~~~
145
+
146
+ ### Weeks
147
+
148
+ You can either get an enumerable list of weeks from an existing year:
149
+
150
+ ~~~~~ ruby
151
+ year.weeks
152
+ # => #<Aef::Weekling::Week: 2014-W01>..#<Aef::Weekling::Week: 2014-W52>
153
+ ~~~~~
154
+
155
+ Or request individual weeks from a year object:
156
+
157
+ ~~~~~ ruby
158
+ year.week(30)
159
+ # => #<Aef::Weekling::Week: 2014-W30>
160
+ ~~~~~
161
+
162
+ Or you can construct a week by year and index (week number):
163
+
164
+ ~~~~~ ruby
165
+ week = Week.new(2012, 37)
166
+ # => #<Aef::Weekling::Week: 2012-W37>
167
+ ~~~~~
168
+
169
+ To regain the year or index you can simply access the attributes:
170
+
171
+ ~~~~~ ruby
172
+ week.year
173
+ # => #<Aef::Weekling::Year: 2012>
174
+
175
+ week.index
176
+ # => 37
177
+ ~~~~~
178
+
179
+ The next or previous weeks can be accessed by the respective methods:
180
+
181
+ ~~~~~ ruby
182
+ week.next
183
+ # => #<Aef::Weekling::Week: 2012-W38>
184
+
185
+ week.previous
186
+ # => #<Aef::Weekling::Week: 2012-W36>
187
+ ~~~~~
188
+
189
+ You can also add or subtract amounts of weeks to get another week object:
190
+
191
+ ~~~~~ ruby
192
+ week + 5
193
+ # => #<Aef::Weekling::Week: 2012-W42>
194
+
195
+ week - 7
196
+ # => #<Aef::Weekling::Week: 2012-W30>
197
+ ~~~~~
198
+
199
+ The week is also able to tell you if it is even or odd:
200
+
201
+ ~~~~~ ruby
202
+ week.even?
203
+ # => false
204
+
205
+ week.odd?
206
+ # => true
207
+ ~~~~~
208
+
209
+ You can also construct a range of weeks starting with the current, which can be
210
+ iterated through or which can be easily converted to an Array. The range will
211
+ run until given index in the future is reached. Notice that this means, if the
212
+ given index is lower or equal to the current, the end of the range will be in
213
+ the following year:
214
+
215
+ ~~~~~ ruby
216
+ week.until_index(45)
217
+ # => #<Aef::Weekling::Week: 2012-W37>..#<Aef::Weekling::Week: 2012-W45>
218
+
219
+ week.until_index(11)
220
+ # => #<Aef::Weekling::Week: 2012-W37>..#<Aef::Weekling::Week: 2013-W11>
221
+ ~~~~~
222
+
223
+ ### Week-days
224
+
225
+ You can either get an enumerable list of week-days from an existing week:
226
+
227
+ ~~~~~ ruby
228
+ week.days
229
+ # => #<Aef::Weekling::WeekDay: 2012-W37-1>..#<Aef::Weekling::WeekDay: 2012-W37-7>
230
+
231
+ week.weekend
232
+ # => [#<Aef::Weekling::WeekDay: 2012-W37-6>, #<Aef::Weekling::WeekDay: 2012-W37-7>]
233
+ ~~~~~
234
+
235
+ Or request individual week-days from a week object:
236
+
237
+ ~~~~~ ruby
238
+ week.day(3)
239
+ # => #<Aef::Weekling::WeekDay: 2012-W37-3>
240
+
241
+ week.day(:friday)
242
+ # => #<Aef::Weekling::WeekDay: 2012-W37-5>
243
+
244
+ week.monday
245
+ # => #<Aef::Weekling::WeekDay: 2012-W37-1>
246
+ ~~~~~
247
+
248
+ Or you can create a week-day by year, week and day. The day can be an index
249
+ between 1 and 7 (monday to sunday), or the lower-case english name of the day
250
+ as symbol. Example below:
251
+
252
+ ~~~~~ ruby
253
+ week_day = WeekDay.new(2012, 37, 4)
254
+ # => #<Aef::Weekling::WeekDay: 2012-W37-4>
255
+
256
+ week_day = WeekDay.new(2012, 37, :thursday)
257
+ # => #<Aef::Weekling::WeekDay: 2012-W37-4>
258
+ ~~~~~
259
+
260
+ To regain the week and the index you can access the attributes:
261
+
262
+ ~~~~~ ruby
263
+ week_day.week
264
+ # => #<Aef::Weekling::Week: 2012-W37>
265
+
266
+ week_day.index
267
+ # => 4
268
+ ~~~~~
269
+
270
+ If you want the symbolized name instead, use the following:
271
+
272
+ ~~~~~ ruby
273
+ week_day.to_sym
274
+ # => :thursday
275
+ ~~~~~
276
+
277
+ As in weeks you can get the next and previous day the following way:
278
+
279
+ ~~~~~ ruby
280
+ week_day.next
281
+ # => #<Aef::Weekling::WeekDay: 2012-W37-5>
282
+
283
+ week_day.previous
284
+ # => #<Aef::Weekling::WeekDay: 2012-W37-3>
285
+ ~~~~~
286
+
287
+ You can also add or subtract amounts of week-days to get another week-day object:
288
+
289
+ ~~~~~ ruby
290
+ week_day + 5
291
+ # => #<Aef::Weekling::WeekDay: 2012-W38-2>
292
+
293
+ week_day - 7
294
+ # => #<Aef::Weekling::WeekDay: 2012-W36-4>
295
+ ~~~~~
296
+
297
+ Each week-day can be converted to a regular date easily:
298
+
299
+ ~~~~~ ruby
300
+ week_day.to_date
301
+ # => #<Date: 2012-09-13 (…)>
302
+ ~~~~~
303
+
304
+ You can ask a week-day if it is a specific day in week:
305
+
306
+ ~~~~~ ruby
307
+ week_day.tuesday?
308
+ # => false
309
+
310
+ week_day.thursday?
311
+ # => true
312
+ ~~~~~
313
+
314
+ Requirements
315
+ ------------
316
+
317
+ None
318
+
319
+ Installation
320
+ ------------
321
+
322
+ On *nix systems you may need to prefix the command with sudo to get root
323
+ privileges.
324
+
325
+ ### High security (recommended)
326
+
327
+ There is a high security installation option available through rubygems. It is
328
+ highly recommended over the normal installation, although it may be a bit less
329
+ comfortable. To use the installation method, you will need my public key, which
330
+ I use for cryptographic signatures on all my gems. You can find the public key
331
+ here: http://aef.name/crypto/aef-gem.pem
332
+
333
+ Add the key to your rubygems' trusted certificates by the following command:
334
+
335
+ gem cert --add aef-gem.pem
336
+
337
+ Now you can install the gem while automatically verifying it's signature by the
338
+ following command:
339
+
340
+ gem install weekling -P HighSecurity
341
+
342
+ Please notice that you may need other keys for dependent libraries, so you may
343
+ have to install dependencies manually.
344
+
345
+ ### Normal
346
+
347
+ gem install weekling
348
+
349
+ ### Automated testing
350
+
351
+ Go into the root directory of the installed gem and run the following command
352
+ to fetch all development dependencies:
353
+
354
+ bundle
355
+
356
+ Afterwards start the test runner:
357
+
358
+ rake spec
359
+
360
+ If something goes wrong you should be noticed through failing examples.
361
+
362
+ Development
363
+ -----------
364
+
365
+ This software is developed in the source code management system git hosted
366
+ at github.com. You can download the most recent sourcecode through the
367
+ following command:
368
+
369
+ git clone https://github.com/aef/weekling.git
370
+
371
+ Help on making this software better is always very appreciated. If you want
372
+ your changes to be included in the official release, please clone my project
373
+ on github.com, create a named branch to commit and push your changes in and
374
+ send me a pull request afterwards.
375
+
376
+ Please make sure to write tests for your changes so that I won't break them
377
+ when changing other things on the library. Also notice that I can't promise
378
+ to include your changes before reviewing them.
379
+
380
+ License
381
+ -------
382
+
383
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
384
+
385
+ This file is part of Weekling.
386
+
387
+ Permission to use, copy, modify, and/or distribute this software for any
388
+ purpose with or without fee is hereby granted, provided that the above
389
+ copyright notice and this permission notice appear in all copies.
390
+
391
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
392
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
393
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
394
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
395
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
396
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
397
+ PERFORMANCE OF THIS SOFTWARE.