active_period 7.1.1 → 7.1.2

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
  SHA256:
3
- metadata.gz: bfac8dacceda500a1902d5294bc1085a70471c3b8d9abf0c0bf039c5e6a5bdba
4
- data.tar.gz: a016fb107d49981e8eb89caf285012277c30b21a46928c460bc7ad9c5f5e80ec
3
+ metadata.gz: e197dc4558fd215fc7090f5a14ad074e769457abfa7665b4b2393e5ba2a23d52
4
+ data.tar.gz: 54c3de6172706d0f08e2885b6401b3f1c964526498193a63c13af4fbfab6eb99
5
5
  SHA512:
6
- metadata.gz: f164a66d035b1f4488a5851fdc9205c2a1836c35c145d63f551fe52038749d86e0c11d6d57eb266aa0c980516e28211a004b0fbe7019335a9ffd29ee0687f22d
7
- data.tar.gz: ec860e7598cf0263def6444a9a119efb04aa3631d9f5c1106a7ca690adb9a0c7d1e413ccfd567cb4e9be61de4613c9a77e54dbe06979dc434fd342e92cf50fd4
6
+ metadata.gz: a228d61ffcb56d1f9206127e22775e2a3ec109822ce0b8242e6e778d8edb08531dd9b2834cc7def80cb42ec7cf148b2abc8776059228c5fb7b7d9cb90ec68562
7
+ data.tar.gz: 25550cbd55706774bfd34e68690be5d39b2e01b6681f33b3134d3c7169949c9e1d017ac40cadd24d041eef2c85d3ce6c05dbb8fe76761d6a2fabebe501230e24
data/Gemfile.lock CHANGED
@@ -1,19 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_period (7.1.0)
5
- activesupport (>= 5, <= 7)
4
+ active_period (7.1.1)
5
+ activesupport (>= 5, < 8)
6
6
  i18n (~> 1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.4)
11
+ activesupport (7.0.4)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
- zeitwerk (~> 2.3)
17
16
  builder (3.2.4)
18
17
  concurrent-ruby (1.1.10)
19
18
  cucumber (7.0.0)
@@ -61,7 +60,6 @@ GEM
61
60
  ffi (~> 1.1)
62
61
  tzinfo (2.0.5)
63
62
  concurrent-ruby (~> 1.0)
64
- zeitwerk (2.6.0)
65
63
 
66
64
  PLATFORMS
67
65
  ruby
@@ -15,8 +15,8 @@ fr:
15
15
  param_must_be_a_range: Le paramètre doit hériter de la class Range
16
16
  free_period:
17
17
  default_format: Du %{from} au %{to} %{ending}
18
- beginless_format: Jusqu'au %{from} %{ending}
19
- endless_format: Depuis le %{to}
18
+ beginless_format: Jusqu'au %{to} %{ending}
19
+ endless_format: Depuis le %{from}
20
20
  boundless_format: Sans limite de temps
21
21
  standard_period:
22
22
  base_class_is_abstract: StandardPeriod est une class abstraite qui ne doit pas être utiliser directement
@@ -1,5 +1,5 @@
1
1
  module ActivePeriod
2
2
 
3
- VERSION = '7.1.1'.freeze
3
+ VERSION = '7.1.2'.freeze
4
4
 
5
5
  end
data/lib/period.rb CHANGED
@@ -50,32 +50,56 @@ module Period
50
50
  alias tomorrow next_day
51
51
  alias today this_day
52
52
 
53
- # Experimental non-documented feature
53
+ LAST_OR_NEXT_REGEX = /^(:?last|next)_(\d+)_(day|week|month|quarter|year)s?(_from_now)?$/
54
+ LAST_AND_NEXT_REGEX = /^last_(\d+)_(day|week|month|quarter|year)s?_to_next_(\d+)_(day|week|month|quarter|year)s?$/
55
+
56
+ # Experimenta l non-documented feature
54
57
  # Inpired form ActiveRecord dynamic find_by_x like User.find_by_name
55
58
  # Example: Period.last_3_weeks_from_now == Period.mew(2.weeks.ago.beginning_of_week..Time.now.end_of_week)
56
- # Note : Maybe it should return a collection of StandardPeriod
57
59
  def method_missing(method_name, *arguments, &block)
58
- super unless method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/)
59
- last_next, count, klass = method_name.to_s.split('_')
60
+ if method_name.match? LAST_OR_NEXT_REGEX
61
+ missing_last_or_next(method_name)
62
+ elsif method_name.match? LAST_AND_NEXT_REGEX
63
+ missing_last_and_next(method_name)
64
+ else
65
+ super
66
+ end
67
+ end
68
+
69
+ def missing_last_or_next(method_name)
70
+ last_next, count, klass, from_now = method_name.to_s.scan(LAST_OR_NEXT_REGEX).flatten
60
71
  klass = klass.singularize
61
72
 
62
73
  case last_next
63
74
  when 'last'
64
75
  from = count.to_i.send(klass).ago.send("beginning_of_#{klass}")
65
76
  to = env_time.now
66
- to -= 1.send(klass) unless method_name.match?(/from_now$/)
77
+ to -= 1.send(klass) unless from_now
67
78
  to = to.send("end_of_#{klass}")
68
79
  when 'next'
69
80
  from = env_time.now
70
- from += 1.send(klass) unless method_name.match?(/from_now$/)
81
+ from += 1.send(klass) unless from_now
71
82
  from = from.send("beginning_of_#{klass}")
72
83
  to = count.to_i.send(klass).from_now.send("end_of_#{klass}")
73
84
  end
74
85
  self.new(from..to)
75
86
  end
76
87
 
88
+ def missing_last_and_next(method_name)
89
+ last_count, last_klass, next_count, next_klass = method_name.to_s.scan(LAST_AND_NEXT_REGEX).flatten
90
+ last_klass = last_klass.singularize
91
+ next_klass = next_klass.singularize
92
+
93
+ from = last_count.to_i.send(last_klass).ago.send("beginning_of_#{last_klass}")
94
+ to = next_count.to_i.send(next_klass).from_now.send("end_of_#{next_klass}")
95
+
96
+ self.new(from..to)
97
+ end
98
+
77
99
  def respond_to_missing?(method_name, include_private = false)
78
- method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/) || super
100
+ method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/) ||
101
+ method_name.match?(/(last)_\d+_(day|week|month|quarter|year)s?_to_next_\d+_(day|week|month|quarter|year)s?/ ) ||
102
+ super
79
103
  end
80
104
  end
81
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_period
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.1
4
+ version: 7.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - billau_l
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.1.2
162
+ rubygems_version: 3.3.22
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: Manage time ranges without brain damage.