dater 0.2.2 → 0.2.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.
Files changed (4) hide show
  1. data/dater.gemspec +1 -1
  2. data/lib/dater/version.rb +1 -1
  3. data/lib/dater.rb +55 -48
  4. metadata +3 -3
data/dater.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["roman.g.rodriguez@gmail.com"]
11
11
  spec.description = %q{This gem aims to help you with dates treatment, specially in regression test where you have to use future dates}
12
12
  spec.summary = %q{Converts periods of time expresed in literal mode to a formatted date from the date of today}
13
- spec.homepage = "https://github.com/gitroman/dater"
13
+ spec.homepage = "http://gitroman.github.io/dater"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
data/lib/dater/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dater
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/dater.rb CHANGED
@@ -43,7 +43,7 @@ module Dater
43
43
  when /\d+.\d+.\d+/
44
44
  time_from_date(period)
45
45
  when /\d+\s.+/
46
- Time.now+period.scan(/\d+/)[0].to_i*self.multiply_by(period,@lang)
46
+ Time.now+period.scan(/\d+/)[0].to_i*multiply_by(period)
47
47
  else
48
48
  return period
49
49
  end
@@ -51,55 +51,14 @@ module Dater
51
51
  return @date.strftime(@format)
52
52
  end
53
53
 
54
- # Set true the matched keyword in a given string
55
- #
56
- # Param [String] period = the period of time expressed in a literal way
57
- # Param [String] lang = the languaje to eval
58
- # Return [Hash] times
59
- def multiply_by(period, lang)
60
- mult = 1
61
- mult = DICTIONARY[:day][:mult] if is_day?(period, lang)
62
- mult = DICTIONARY[:week][:mult] if is_week?(period, lang)
63
- mult = DICTIONARY[:month][:mult] if is_month?(period, lang)
64
- mult = DICTIONARY[:year][:mult] if is_year?(period, lang)
65
- return mult
66
- end
67
-
68
- def is_day?(period, lang)
69
- period.scan(DICTIONARY[:day][lang]).size > 0 ? true : false
70
- end
71
-
72
- def is_week?(period, lang)
73
- period.scan(DICTIONARY[:week][lang]).size > 0 ? true : false
74
- end
75
-
76
- def is_month?(period, lang)
77
- period.scan(DICTIONARY[:month][lang]).size > 0 ? true : false
78
- end
79
-
80
- def is_year?(period, lang)
81
- period.scan(DICTIONARY[:year][lang]).size > 0 ? true : false
82
- end
83
-
84
- # Return the Time object according to the splitted date in the given array
85
- # |
86
- # Param [Array] date = date splitted
87
- # Return [Time]
88
- def time_from_date(date)
89
- numbers=date.scan(/\d+/).map!{|i| i.to_i}
90
- if numbers.first.to_s.size==4
91
- return Date.new(numbers[0],numbers[1],numbers[2]).to_time
92
- else
93
- return Date.new(numbers[2],numbers[1],numbers[0]).to_time
94
- end
95
- end
96
-
97
54
  def para(period)
98
55
  self.for(period)
99
56
  end
100
57
 
101
58
  def today(formatted=true)
102
- formatted ? Time.now.strftime(@format) :Time.now
59
+ time=Time.now
60
+ time=time.strftime(@format) if formatted
61
+ time
103
62
  end
104
63
 
105
64
  def hoy
@@ -111,7 +70,9 @@ module Dater
111
70
  end
112
71
 
113
72
  def yesterday(formatted=true)
114
- formatted ? (Time.now-(3600*24)).strftime(@format) : Time.now-(3600*24)
73
+ time=Time.now-(3600*24)
74
+ time=time.strftime(@format) if formatted
75
+ time
115
76
  end
116
77
 
117
78
  def ayer
@@ -123,7 +84,9 @@ module Dater
123
84
  end
124
85
 
125
86
  def tomorrow(formatted=true)
126
- formatted ? (Time.now+(3600*24)).strftime(@format) : (Time.now+(3600*24))
87
+ time=Time.now+(3600*24)
88
+ time=time.strftime(@format) if formatted
89
+ time
127
90
  end
128
91
 
129
92
  def mañana
@@ -134,5 +97,49 @@ module Dater
134
97
  self.tomorrow(true)
135
98
  end
136
99
 
100
+ private
101
+
102
+ def day_mult(period)
103
+ period.scan(DICTIONARY[:day][@lang]).size > 0 ? DICTIONARY[:day][:mult] : nil
104
+ end
105
+
106
+ def week_mult(period)
107
+ period.scan(DICTIONARY[:week][@lang]).size > 0 ? DICTIONARY[:week][:mult] : nil
108
+ end
109
+
110
+ def month_mult(period)
111
+ period.scan(DICTIONARY[:month][@lang]).size > 0 ? DICTIONARY[:month][:mult] : nil
112
+ end
113
+
114
+ def year_mult(period)
115
+ period.scan(DICTIONARY[:year][@lang]).size > 0 ? DICTIONARY[:year][:mult] : nil
116
+ end
117
+
118
+ # Set true the matched keyword in a given string
119
+ #
120
+ # Param [String] period = the period of time expressed in a literal way
121
+ # Param [String] lang = the languaje to eval
122
+ # Return [Hash] times
123
+ def multiply_by(period)
124
+
125
+ return day_mult(period) || week_mult(period) || month_mult(period) || year_mult(period) || 1
126
+ # mult = 1
127
+ # mult = DICTIONARY[:day][:mult] if day_mult(period)
128
+ # mult = DICTIONARY[:week][:mult] if week_mult(period)
129
+ # mult = DICTIONARY[:month][:mult] if month_mult(period)
130
+ # mult = DICTIONARY[:year][:mult] if year_mult(period)
131
+ # return mult
132
+ end
133
+
134
+
135
+ # Return the Time object according to the splitted date in the given array
136
+ # |
137
+ # Param [Array] date = date splitted
138
+ # Return [Time]
139
+ def time_from_date(date)
140
+ numbers=date.scan(/\d+/).map!{|i| i.to_i}
141
+ day=numbers[2-numbers.index(numbers.max)]
142
+ Date.new(numbers.max,numbers[1],day).to_time
143
+ end
137
144
  end
138
- end
145
+ 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.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-07 00:00:00.000000000 Z
12
+ date: 2013-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -60,7 +60,7 @@ files:
60
60
  - dater.gemspec
61
61
  - lib/dater.rb
62
62
  - lib/dater/version.rb
63
- homepage: https://github.com/gitroman/dater
63
+ homepage: http://gitroman.github.io/dater
64
64
  licenses:
65
65
  - MIT
66
66
  post_install_message: