what_date 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/what_date/client.rb +6 -0
- data/lib/what_date/date_of_month.rb +12 -8
- data/lib/what_date/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 589b27a457943401b0029d5896071f4fd44678ca
|
4
|
+
data.tar.gz: c51e60d504a9e233eb9ebb506d5668b5a72b49c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1357c088824ba1e953f5d5ae676a13c04a0df97f7305e476421baccab89c78f6526a53fc0eb87e8728bd801f745b59ef876c37b34a0271c6fd097e87285181b4
|
7
|
+
data.tar.gz: aa9827cbac19ebbd6042fcb82f9d7a3d04700ac7b06a163a3a2865105df5d82871227aa5d6bd7e55a873d6f467c1eba7fb856baffec60346bd1ab1008d4f1ee9
|
data/README.md
CHANGED
@@ -25,8 +25,9 @@ $client = WhatDate.client
|
|
25
25
|
## get dates
|
26
26
|
client.friday
|
27
27
|
client.tuesday(Date.new(2018,2,3)) ##date of tuesday in the week of the given date
|
28
|
-
client.prev_tuesday
|
28
|
+
client.prev_tuesday ## same as client.last_tuesday
|
29
29
|
client.next_tuesday
|
30
|
+
client.next_tuesday Date.new(2018,2,3) ## the following tuesday after the week of the given date
|
30
31
|
|
31
32
|
```
|
32
33
|
You can also ask for the date of a particular day of a given month. Use ordinals such as first, second and up to fifth. You can enquire the last date too.
|
@@ -41,6 +42,11 @@ client.third_tuesday_of_may_2018
|
|
41
42
|
client.last_monday_of_may_2018
|
42
43
|
##28 May 2018
|
43
44
|
|
45
|
+
## default to current year
|
46
|
+
## Date.today.year == 2018
|
47
|
+
client.last_monday_of_may
|
48
|
+
##28 May 2018
|
49
|
+
|
44
50
|
```
|
45
51
|
|
46
52
|
## Development
|
data/lib/what_date/client.rb
CHANGED
@@ -20,6 +20,12 @@ module WhatDate
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
Date::DAYS_INTO_WEEK.each do |day, inc|
|
24
|
+
define_method("last_#{day.to_s}".to_sym) do |ref_date = nil|
|
25
|
+
send("prev_#{day.to_s}".to_sym, ref_date)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
23
29
|
Date::DAYS_INTO_WEEK.each do |day, inc|
|
24
30
|
define_method("next_#{day.to_s}".to_sym) do |ref_date = nil|
|
25
31
|
send(day, ref_date).days_since(7)
|
@@ -2,9 +2,9 @@ module WhatDate
|
|
2
2
|
module DateOfMonth
|
3
3
|
|
4
4
|
ORDINALS ={ "first" => 1, "second" => 2, "third" => 3, "fourth" => 4, "fifth" => 5, "last" => nil }.freeze
|
5
|
-
ORDERS = '
|
6
|
-
WEEKDAYS = '
|
7
|
-
MONTHS = '
|
5
|
+
ORDERS = 'first||second||third||fourth||fifth||last'.freeze
|
6
|
+
WEEKDAYS = 'monday||tuesday||wednesday||thursday||friday||saturday||sunday'.freeze
|
7
|
+
MONTHS = 'january||february||march||april||may||june||july||august||september||october||november||december'.freeze
|
8
8
|
|
9
9
|
|
10
10
|
def date_of_month(order:1, day:, month:, year: Date.today.year)
|
@@ -25,12 +25,12 @@ module WhatDate
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def method_missing(name, *args, &block)
|
28
|
-
|
29
|
-
|
30
|
-
order = ORDINALS[methods[
|
31
|
-
day = format_date_string methods[
|
28
|
+
methods = missing_method_reg.match(name)
|
29
|
+
if methods
|
30
|
+
order = ORDINALS[methods[1].downcase]
|
31
|
+
day = format_date_string methods[2]
|
32
32
|
month = format_date_string methods[3]
|
33
|
-
year = methods[4].to_i
|
33
|
+
year = methods[4] ? methods[4][/\d+/].to_i : Date.today.year
|
34
34
|
order == nil ? date_of_last_week_day_in_month(day, month, year) :
|
35
35
|
date_of_month(order: order, day: day, month: month, year: year)
|
36
36
|
else
|
@@ -48,6 +48,10 @@ module WhatDate
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
+
def missing_method_reg
|
52
|
+
Regexp.new("^(#{ORDERS})_(#{WEEKDAYS})_of_(#{MONTHS})(_\\d+)?$", true)
|
53
|
+
end
|
54
|
+
|
51
55
|
def format_date_string(str)
|
52
56
|
str.downcase.capitalize
|
53
57
|
end
|
data/lib/what_date/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|