what_date 0.1.2 → 0.1.3

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
2
  SHA1:
3
- metadata.gz: 7f4e7f5299beb9358ddb950978a85d43345a1ba2
4
- data.tar.gz: 4f1014d45467de87328c5daed2c4b3a021db2fca
3
+ metadata.gz: 589b27a457943401b0029d5896071f4fd44678ca
4
+ data.tar.gz: c51e60d504a9e233eb9ebb506d5668b5a72b49c0
5
5
  SHA512:
6
- metadata.gz: c89b1f0e607cba9b25fe4247169f4e6290dbece02bd43654e93f653620c1949b56a51afa7330ea5171a91f744553458833f0a79a9730fbe98d23e7483059f5fb
7
- data.tar.gz: b2c1e9b149a29d4717b30ae8c0739de66e19dd09e47687eb38c467677d3bac1822554339fa3575f83f857f13892b388f67c5af040a5cab8ad820c423912d8a77
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
@@ -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 = '(first||second||third||fourth||fifth||last)'.freeze
6
- WEEKDAYS = '(monday||tuesday||wednesday||thursday||friday||saturday||sunday)'.freeze
7
- MONTHS = '(jan||feb||mar||apr||may||jun||jul||aug||sep||oct||nov||dec||january||february||march||april||may||june||july||august||september||october||november||december||sept)'.freeze
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
- if name.to_s =~ Regexp.new("^#{ORDERS}_#{WEEKDAYS}_of_#{MONTHS}_\\d+$", true)
29
- methods = name.to_s.split("_")
30
- order = ORDINALS[methods[0].downcase]
31
- day = format_date_string methods[1]
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
@@ -1,3 +1,3 @@
1
1
  module WhatDate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-30 00:00:00.000000000 Z
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport