active_object 4.0.14 → 5.0.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,103 +1,109 @@
1
- module ActiveObject::Date
2
- MINUTE ||= 60.0
3
- HOUR ||= MINUTE * 60.0
4
- DAY ||= HOUR * 24.0
5
- WEEK ||= DAY * 7.0
6
- YEAR ||= DAY * 365.25
7
- DECADE ||= YEAR * 10.0
8
- CENTURY ||= DECADE * 10.0
9
- MILLENNIUM ||= CENTURY * 10.0
10
-
11
- STRING_UNITS ||= {
12
- d: 'd', day: 'd', day_padded: 'd', dd: '-d', Day: '-d', day_unpadded: '-d', ddd: '_d',
13
- DAY: '_d', day_blank: '_d', dddd: 'j', day_of_the_year: 'j', m: 'm', month: 'm', yyyy: 'Y',
14
- month_padded: 'm', mm: '-m', Month: '-m', month_unpadded: '-m', mmm: '_m', MONTH: '_m',
15
- month_blank: '_m', mmmm: 'B', month_name: 'B', mmmmm: 'b', month_name_abbr: 'b', w: 'u',
16
- weekday: 'u', ww: 'w', weekday_offset: 'w', www: 'A', weekday_name: 'A', wwww: 'a', year: 'Y',
17
- weekday_name_abbr: 'a', yy: 'y', yr: 'y', swe: 'U', sunday_week: 'U', mwe: 'W',
18
- monday_week: 'W', we: 'V', week: 'V'
19
- }.freeze
20
- KEY_UNITS ||= {
21
- month: '%m', month_padded: '%m', month_unpadded: '%-m', month_blank: '%_m', month_name: '%B',
22
- month_name_abbr: '%b', month_year: '%m %Y', month_padded_year: '%m %Y', day_iso: '%m-%d',
23
- month_unpadded_year: '%-m %Y', month_blank_year: '%_m %Y', month_name_year: '%B %Y',
24
- month_name_abbr_year: '%b %Y', weekday: '%d', weekday_padded: '%d', weekday_unpadded: '%-d',
25
- weekday_blank: '%_d', weekday_name: '%A', weekday_name_abbr: '%a', yr: '%y', year_abbr: '%y',
26
- year: '%Y', date: '%B %-d, %Y', date_abbr: '%b %-d, %Y', date_iso: '%Y-%m-%d', day: '%B %-d',
27
- day_abbr: '%b %-d', sunday_week: '%U', monday_week: '%W', week_iso: '%V', week_year_iso: '%V-%G'
28
- }.freeze
29
-
30
- def count_centuries_since(time)
31
- count_seconds_since(time) / CENTURY
32
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module ActiveObject
6
+ module Date
7
+ MINUTE ||= 60.0
8
+ HOUR ||= MINUTE * 60.0
9
+ DAY ||= HOUR * 24.0
10
+ WEEK ||= DAY * 7.0
11
+ YEAR ||= DAY * 365.25
12
+ DECADE ||= YEAR * 10.0
13
+ CENTURY ||= DECADE * 10.0
14
+ MILLENNIUM ||= CENTURY * 10.0
15
+
16
+ STRING_UNITS ||= {
17
+ d: 'd', day: 'd', day_padded: 'd', dd: '-d', Day: '-d', day_unpadded: '-d', ddd: '_d',
18
+ DAY: '_d', day_blank: '_d', dddd: 'j', day_of_the_year: 'j', m: 'm', month: 'm', yyyy: 'Y',
19
+ month_padded: 'm', mm: '-m', Month: '-m', month_unpadded: '-m', mmm: '_m', MONTH: '_m',
20
+ month_blank: '_m', mmmm: 'B', month_name: 'B', mmmmm: 'b', month_name_abbr: 'b', w: 'u',
21
+ weekday: 'u', ww: 'w', weekday_offset: 'w', www: 'A', weekday_name: 'A', wwww: 'a', year: 'Y',
22
+ weekday_name_abbr: 'a', yy: 'y', yr: 'y', swe: 'U', sunday_week: 'U', mwe: 'W',
23
+ monday_week: 'W', we: 'V', week: 'V'
24
+ }.freeze
25
+ KEY_UNITS ||= {
26
+ month: '%m', month_padded: '%m', month_unpadded: '%-m', month_blank: '%_m', month_name: '%B',
27
+ month_name_abbr: '%b', month_year: '%m %Y', month_padded_year: '%m %Y', day_iso: '%m-%d',
28
+ month_unpadded_year: '%-m %Y', month_blank_year: '%_m %Y', month_name_year: '%B %Y',
29
+ month_name_abbr_year: '%b %Y', weekday: '%d', weekday_padded: '%d', weekday_unpadded: '%-d',
30
+ weekday_blank: '%_d', weekday_name: '%A', weekday_name_abbr: '%a', yr: '%y', year_abbr: '%y',
31
+ year: '%Y', date: '%B %-d, %Y', date_abbr: '%b %-d, %Y', date_iso: '%Y-%m-%d', day: '%B %-d',
32
+ day_abbr: '%b %-d', sunday_week: '%U', monday_week: '%W', week_iso: '%V', week_year_iso: '%V-%G'
33
+ }.freeze
34
+
35
+ def count_centuries_since(time)
36
+ count_seconds_since(time) / CENTURY
37
+ end
33
38
 
34
- alias_method :count_centuries_until, :count_centuries_since
39
+ alias_method :count_centuries_until, :count_centuries_since
35
40
 
36
- def count_days_since(time)
37
- count_seconds_since(time) / DAY
38
- end
41
+ def count_days_since(time)
42
+ count_seconds_since(time) / DAY
43
+ end
39
44
 
40
- alias_method :count_days_until, :count_days_since
45
+ alias_method :count_days_until, :count_days_since
41
46
 
42
- def count_decades_since(time)
43
- count_seconds_since(time) / DECADE
44
- end
47
+ def count_decades_since(time)
48
+ count_seconds_since(time) / DECADE
49
+ end
45
50
 
46
- alias_method :count_decades_until, :count_decades_since
51
+ alias_method :count_decades_until, :count_decades_since
47
52
 
48
- def count_hours_since(time)
49
- count_seconds_since(time) / HOUR
50
- end
53
+ def count_hours_since(time)
54
+ count_seconds_since(time) / HOUR
55
+ end
51
56
 
52
- alias_method :count_hours_until, :count_hours_since
57
+ alias_method :count_hours_until, :count_hours_since
53
58
 
54
- def count_milleniums_since(time)
55
- count_seconds_since(time) / MILLENNIUM
56
- end
59
+ def count_milleniums_since(time)
60
+ count_seconds_since(time) / MILLENNIUM
61
+ end
57
62
 
58
- alias_method :count_milleniums_until, :count_milleniums_since
63
+ alias_method :count_milleniums_until, :count_milleniums_since
59
64
 
60
- def count_minutes_since(time)
61
- count_seconds_since(time) / MINUTE
62
- end
65
+ def count_minutes_since(time)
66
+ count_seconds_since(time) / MINUTE
67
+ end
63
68
 
64
- alias_method :count_minutes_until, :count_minutes_since
69
+ alias_method :count_minutes_until, :count_minutes_since
65
70
 
66
- def count_seconds_since(time)
67
- (to_time.to_f - time.to_time.to_f).abs
68
- end
71
+ def count_seconds_since(time)
72
+ (to_time.to_f - time.to_time.to_f).abs
73
+ end
69
74
 
70
- alias_method :count_seconds_until, :count_seconds_since
75
+ alias_method :count_seconds_until, :count_seconds_since
71
76
 
72
- def count_weeks_since(time)
73
- count_seconds_since(time) / WEEK
74
- end
77
+ def count_weeks_since(time)
78
+ count_seconds_since(time) / WEEK
79
+ end
75
80
 
76
- alias_method :count_weeks_until, :count_weeks_since
81
+ alias_method :count_weeks_until, :count_weeks_since
77
82
 
78
- def count_years_since(time)
79
- count_seconds_since(time) / YEAR
80
- end
83
+ def count_years_since(time)
84
+ count_seconds_since(time) / YEAR
85
+ end
81
86
 
82
- alias_method :count_years_until, :count_years_since
87
+ alias_method :count_years_until, :count_years_since
83
88
 
84
- def format(string)
85
- delimiters = string.scan(/\W+/)
86
- formatters = string.scan(/[a-z0-9_]+/i)
89
+ def format(string)
90
+ delimiters = string.scan(/\W+/)
91
+ formatters = string.scan(/[a-z0-9_]+/i)
87
92
 
88
- string = formatters.map do |unit|
89
- "%#{STRING_UNITS.fetch(unit.to_sym)}#{delimiters.shift || ''}"
90
- end
93
+ string = formatters.map do |unit|
94
+ "%#{STRING_UNITS.fetch(unit.to_sym)}#{delimiters.shift || ''}"
95
+ end
91
96
 
92
- strftime(string.join)
93
- end
97
+ strftime(string.join)
98
+ end
94
99
 
95
- def to_format(key = :datetime_iso)
96
- strftime(KEY_UNITS.fetch(key.to_sym))
97
- end
100
+ def to_format(key = :datetime_iso)
101
+ strftime(KEY_UNITS.fetch(key.to_sym))
102
+ end
98
103
 
99
- alias_method :stamp, :to_format
104
+ alias_method :stamp, :to_format
100
105
 
106
+ end
101
107
  end
102
108
 
103
- Date.include(ActiveObject::Date) if ActiveObject::Settings.config.autoload_date
109
+ Date.include(ActiveObject::Date) if ActiveObject.configuration.autoload_date
@@ -1,5 +1,6 @@
1
- module Enumerable
1
+ # frozen_string_literal: true
2
2
 
3
+ module Enumerable
3
4
  CRITICAL_ZSCORE ||= {
4
5
  3 => 1.15,
5
6
  4 => 1.48,
@@ -134,7 +135,7 @@ module Enumerable
134
135
  end
135
136
 
136
137
  def frequencies
137
- each_with_object(Hash.new(0)) { |key, hsh| hsh[key] += 1 }
138
+ each_with_object(::Hash.new(0)) { |key, hsh| hsh[key] += 1 }
138
139
  end
139
140
 
140
141
  # rubocop:disable Style/CaseEquality
@@ -184,7 +185,7 @@ module Enumerable
184
185
  def mode(identity = 0)
185
186
  return identity unless length.positive?
186
187
 
187
- frequency_distribution = each_with_object(Hash.new(0)) { |val, hsh| hsh[val] += 1 }
188
+ frequency_distribution = each_with_object(::Hash.new(0)) { |val, hsh| hsh[val] += 1 }
188
189
  frequency_top_two = frequency_distribution.sort_by { |_, val| -val }.take(2)
189
190
  top_two_first = frequency_top_two.first
190
191
 
@@ -248,13 +249,13 @@ module Enumerable
248
249
  else
249
250
  each { |opt| found_count += 1 if opt }
250
251
  end
251
- found_count > 1 ? true : false
252
+ found_count > 1
252
253
  end
253
254
 
254
255
  def standard_deviation(identity = 0)
255
256
  return identity if length < 2
256
257
 
257
- Math.sqrt(variance)
258
+ ::Math.sqrt(variance)
258
259
  end
259
260
 
260
261
  def sum(identity = 0, &block)