week 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/LICENSE +20 -0
  3. data/README.md +3 -0
  4. data/lib/week.rb +70 -0
  5. metadata +69 -0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.0.1 (June 16, 2011)
2
+
3
+ Features:
4
+
5
+ - initial import of this dummy gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Sergey Gerasimov (http://grsmv.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ A simple gem to work with weeks as arrays of days numbers.
2
+
3
+ Copyright (c) 2011 Sergey Gerasimov
data/lib/week.rb ADDED
@@ -0,0 +1,70 @@
1
+
2
+ require 'date'
3
+
4
+ class Numeric
5
+ def days
6
+ self * 60 * 60 * 24
7
+ end
8
+ end
9
+
10
+ # TODO: - write RDoc documentation
11
+ # - empty values as parameters
12
+ class Week
13
+
14
+ def initialize(year, week, fday = 0)
15
+ @year, @week, @fday = year, week, fday
16
+ end
17
+
18
+ class << self
19
+ def nmonth year
20
+ nmonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
21
+ nmonth[1] = Date.new(year, 1, 1).leap? ? 29 : 28
22
+ nmonth
23
+ end
24
+ end
25
+
26
+ def days
27
+ tmp_wday = @week * 7
28
+
29
+ common_days, month_number = 0, 0
30
+
31
+ Week.nmonth(@year).each_with_index do |month, number|
32
+ if (common_days..(common_days + month)).member?(tmp_wday)
33
+ month_number = number
34
+ break
35
+ end
36
+ common_days += month
37
+ end
38
+
39
+ tmp_first_day = tmp_wday - common_days - 7
40
+
41
+ # fixing day number for calculate first week of the year
42
+ tmp_first_day = tmp_first_day == 0 ? 1 : tmp_first_day
43
+
44
+ # fixing problem with last week in month
45
+ if tmp_first_day == -1
46
+ month_number = 11
47
+ tmp_first_day = Week.nmonth(@year)[month_number] - 2
48
+ end
49
+
50
+ # getting week listing
51
+ days = []
52
+ d = Time.local(@year, month_number + 1, tmp_first_day)
53
+ first_day = d - d.wday.days
54
+ @fday.upto(@fday + 6) do |day|
55
+ days << Time.at(first_day + day.days)
56
+ end
57
+
58
+ days
59
+ end
60
+ end
61
+
62
+ # Simpler API for Week class usage
63
+ def Week(year, week, fday = 0)
64
+ Week.new(year, week, fday).days
65
+ end
66
+
67
+ #Week(2011, 1).map do |day|
68
+ # p day
69
+ #end
70
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: week
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sergey Gerasimov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-16 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Simple gem to work with weeks as arrays of day numbers.
22
+ email:
23
+ - mail@grsmv.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - CHANGELOG.md
33
+ - LICENSE
34
+ - lib/week.rb
35
+ homepage: http://github.com/grsmv/week
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: week
64
+ rubygems_version: 1.8.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Simple gem to work with weeks as arrays of day numbers.
68
+ test_files: []
69
+