dater 0.2.0 → 0.2.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dater (0.1.2)
4
+ dater (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -37,7 +37,8 @@ Or install it yourself as:
37
37
 
38
38
  #To get the converted date:
39
39
 
40
- date.for("in 2 days") # => yyyy-mm-dd (date for 2 days from the date of today)
40
+ date.for("in 4 days") # => yyyy-mm-dd (date for 4 days from the date of today)
41
+ date.for("in 2 weeks") # => yyyy-mm-dd (date for 2 weeks from the date of today)
41
42
  date.for("in 10 months") # => yyyy-mm-dd (date for 10 months from the date of today)
42
43
  date.for("in 1 year") # => yyyy-mm-dd (date for 1 year from the date of today)
43
44
 
@@ -46,19 +46,7 @@ module Dater
46
46
  parts=period.split('-')
47
47
  else
48
48
  if (amount=period.scan(/\d+/)).size>0
49
- times=self.eval_times(period, @lang)
50
- if times[:year]
51
- multiply_by = 3600*24*30*12
52
- elsif times[:months]
53
- multiply_by = 3600*24*30
54
- elsif times[:weeks]
55
- multiply_by = 3600*24*7
56
- elsif times[:days]
57
- multiply_by = 3600*24
58
- else
59
- multiply_by = 1
60
- end
61
- additional=amount[0].to_i*multiply_by
49
+ additional=amount[0].to_i*self.multiply_by(period,@lang)
62
50
  @date=Time.now+additional
63
51
  else
64
52
  return period
@@ -73,13 +61,12 @@ module Dater
73
61
  # Param [String] period = the period of time expressed in a literal way
74
62
  # Param [String] lang = the languaje to eval
75
63
  # Return [Hash] times
76
- def eval_times(period, lang)
77
- times = {}
78
- times[:days] = true if period.scan(DICTIONARY[:day][lang]).size>0
79
- times[:weeks] = true if period.scan(DICTIONARY[:week][lang]).size>0
80
- times[:months] = true if period.scan(DICTIONARY[:month][lang]).size>0
81
- times[:year] = true if period.scan(DICTIONARY[:year][lang]).size>0
82
- times
64
+ def multiply_by(period, lang)
65
+ return 3600*24 if period.scan(DICTIONARY[:day][lang]).size>0
66
+ return 3600*24*7 if period.scan(DICTIONARY[:week][lang]).size>0
67
+ return 3600*24*30 if period.scan(DICTIONARY[:month][lang]).size>0
68
+ return 3600*24*30*12 if period.scan(DICTIONARY[:year][lang]).size>0
69
+ return 1
83
70
  end
84
71
 
85
72
  # Return the Time object according to the splitted date in the given array
@@ -1,3 +1,3 @@
1
1
  module Dater
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: