lite-ruby 1.0.14 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,105 +1,107 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Lite
4
- module Ruby
5
- module DateHelper
3
+ if Lite::Ruby.configuration.monkey_patches.include?('date')
4
+ module Lite
5
+ module Ruby
6
+ module DateHelper
6
7
 
7
- DATE_STAMPS ||= {
8
- weekday: '%d',
9
- weekday_blank: '%_d',
10
- weekday_padded: '%d',
11
- weekday_unpadded: '%-d',
12
- weekday_name: '%A',
13
- weekday_name_abbr: '%a',
14
- month: '%m',
15
- month_blank: '%_m',
16
- month_padded: '%m',
17
- month_unpadded: '%-m',
18
- month_name: '%B',
19
- month_name_abbr: '%b',
20
- week_iso: '%V',
21
- week_monday: '%W',
22
- week_sunday: '%U',
23
- year: '%Y',
24
- yr: '%y',
25
- year_abbr: '%y',
26
- day: '%B %-d',
27
- day_abbr: '%b %-d',
28
- day_iso: '%m-%d',
29
- month_year: '%m %Y',
30
- month_blank_year: '%_m %Y',
31
- month_padded_year: '%m %Y',
32
- month_unpadded_year: '%-m %Y',
33
- month_name_year: '%B %Y',
34
- month_name_abbr_year: '%b %Y',
35
- week_year_iso: '%V-%G',
36
- year_day: '%Y-%m-%d',
37
- year_month: '%Y-%m',
38
- year_week: '%G-%V',
39
- date: '%B %-d, %Y',
40
- date_abbr: '%b %-d, %Y',
41
- date_iso: '%Y-%m-%d'
42
- }.freeze
43
- DATE_UNITS ||= {
44
- w: 'u',
45
- weekday: 'u',
46
- ww: 'w',
47
- weekday_offset: 'w',
48
- www: 'A',
49
- weekday_name: 'A',
50
- wwww: 'a',
51
- weekday_name_abbr: 'a',
52
- d: 'd',
53
- day: 'd',
54
- day_padded: 'd',
55
- dd: '-d',
56
- Day: '-d',
57
- day_unpadded: '-d',
58
- ddd: '_d',
59
- DAY: '_d',
60
- day_blank: '_d',
61
- dddd: 'j',
62
- day_of_the_year: 'j',
63
- m: 'm',
64
- month: 'm',
65
- month_padded: 'm',
66
- mm: '-m',
67
- Month: '-m',
68
- month_unpadded: '-m',
69
- mmm: '_m',
70
- MONTH: '_m',
71
- month_blank: '_m',
72
- mmmm: 'B',
73
- month_name: 'B',
74
- mmmmm: 'b',
75
- month_name_abbr: 'b',
76
- swe: 'U',
77
- sunday_week: 'U',
78
- mwe: 'W',
79
- monday_week: 'W',
80
- we: 'V',
81
- week: 'V',
82
- yy: 'y',
83
- yr: 'y',
84
- year: 'Y',
85
- yyyy: 'Y'
86
- }.freeze
8
+ DATE_STAMPS ||= {
9
+ weekday: '%d',
10
+ weekday_blank: '%_d',
11
+ weekday_padded: '%d',
12
+ weekday_unpadded: '%-d',
13
+ weekday_name: '%A',
14
+ weekday_name_abbr: '%a',
15
+ month: '%m',
16
+ month_blank: '%_m',
17
+ month_padded: '%m',
18
+ month_unpadded: '%-m',
19
+ month_name: '%B',
20
+ month_name_abbr: '%b',
21
+ week_iso: '%V',
22
+ week_monday: '%W',
23
+ week_sunday: '%U',
24
+ year: '%Y',
25
+ yr: '%y',
26
+ year_abbr: '%y',
27
+ day: '%B %-d',
28
+ day_abbr: '%b %-d',
29
+ day_iso: '%m-%d',
30
+ month_year: '%m %Y',
31
+ month_blank_year: '%_m %Y',
32
+ month_padded_year: '%m %Y',
33
+ month_unpadded_year: '%-m %Y',
34
+ month_name_year: '%B %Y',
35
+ month_name_abbr_year: '%b %Y',
36
+ week_year_iso: '%V-%G',
37
+ year_day: '%Y-%m-%d',
38
+ year_month: '%Y-%m',
39
+ year_week: '%G-%V',
40
+ date: '%B %-d, %Y',
41
+ date_abbr: '%b %-d, %Y',
42
+ date_iso: '%Y-%m-%d'
43
+ }.freeze
44
+ DATE_UNITS ||= {
45
+ w: 'u',
46
+ weekday: 'u',
47
+ ww: 'w',
48
+ weekday_offset: 'w',
49
+ www: 'A',
50
+ weekday_name: 'A',
51
+ wwww: 'a',
52
+ weekday_name_abbr: 'a',
53
+ d: 'd',
54
+ day: 'd',
55
+ day_padded: 'd',
56
+ dd: '-d',
57
+ Day: '-d',
58
+ day_unpadded: '-d',
59
+ ddd: '_d',
60
+ DAY: '_d',
61
+ day_blank: '_d',
62
+ dddd: 'j',
63
+ day_of_the_year: 'j',
64
+ m: 'm',
65
+ month: 'm',
66
+ month_padded: 'm',
67
+ mm: '-m',
68
+ Month: '-m',
69
+ month_unpadded: '-m',
70
+ mmm: '_m',
71
+ MONTH: '_m',
72
+ month_blank: '_m',
73
+ mmmm: 'B',
74
+ month_name: 'B',
75
+ mmmmm: 'b',
76
+ month_name_abbr: 'b',
77
+ swe: 'U',
78
+ sunday_week: 'U',
79
+ mwe: 'W',
80
+ monday_week: 'W',
81
+ we: 'V',
82
+ week: 'V',
83
+ yy: 'y',
84
+ yr: 'y',
85
+ year: 'Y',
86
+ yyyy: 'Y'
87
+ }.freeze
87
88
 
88
- def format(string = nil)
89
- string ||= default_format
90
- delimiters = string.scan(/\W+/)
91
- formatters = string.scan(/[a-z0-9_]+/i)
92
- string = formatters.map { |key| "%#{format_for(key.to_sym)}#{delimiters.shift}" }
93
- strftime(string.join)
94
- end
89
+ def format(string = nil)
90
+ string ||= default_format
91
+ delimiters = string.scan(/\W+/)
92
+ formatters = string.scan(/[a-z0-9_]+/i)
93
+ string = formatters.map { |key| "%#{format_for(key.to_sym)}#{delimiters.shift}" }
94
+ strftime(string.join)
95
+ end
95
96
 
96
- def stamp(key = nil)
97
- key = stamp_for(key&.to_sym || default_stamp)
98
- strftime(key)
99
- end
97
+ def stamp(key = nil)
98
+ key = stamp_for(key&.to_sym || default_stamp)
99
+ strftime(key)
100
+ end
100
101
 
101
- alias to_format stamp
102
+ alias to_format stamp
102
103
 
104
+ end
103
105
  end
104
106
  end
105
107
  end
@@ -1,84 +1,86 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Lite
4
- module Ruby
5
- module TimeHelper
3
+ if Lite::Ruby.configuration.monkey_patches.include?('time')
4
+ module Lite
5
+ module Ruby
6
+ module TimeHelper
6
7
 
7
- TIME_STAMPS ||= {
8
- hour: '%H',
9
- hour_blank: '%k',
10
- hour_padded: '%H',
11
- hour_12: '%I',
12
- hour_12_padded: '%I',
13
- hour_12_blank: '%l',
14
- minute: '%M',
15
- second: '%S',
16
- ampm: '%P',
17
- meridian: '%p',
18
- time_zone: '%z',
19
- time_zone_offset: '%:z',
20
- time_zone_offset_full: '%::z',
21
- time_zone_name: '%Z',
22
- time: '%H:%M',
23
- time_blank: '%k:%M',
24
- time_padded: '%H:%M',
25
- time_tz: '%H:%M %z',
26
- time_tzn: '%H:%M %Z',
27
- time_12: '%I:%M %P',
28
- time_12_padded: '%I:%M %P',
29
- time_12_blank: '%l:%M %P',
30
- time_12_tz: '%I:%M %P %z',
31
- time_12_tzn: '%I:%M %P %Z',
32
- daytime: '%B %-d %H:%M',
33
- daytime_abbr: '%b %-d %H:%M',
34
- daytime_iso: '%m-%d %H:%M',
35
- daytime_12: '%B %-d %I:%M %P',
36
- daytime_12_abbr: '%b %-d %I:%M %P',
37
- daytime_12_iso: '%m-%d %I:%M %P',
38
- datetime: '%B %-d, %Y %H:%M',
39
- datetime_abbr: '%b %-d, %Y %H:%M',
40
- datetime_iso: '%Y-%m-%d %H:%M',
41
- datetime_12: '%B %-d, %Y %I:%M %P',
42
- datetime_12_abbr: '%b %-d, %Y %I:%M %P',
43
- datetime_12_iso: '%Y-%m-%d %I:%M %P',
44
- datetime_tzn: '%B %-d, %Y %H:%M %Z',
45
- datetime_abbr_tzn: '%b %-d, %Y %H:%M %Z',
46
- datetime_iso_tzn: '%Y-%m-%d %H:%M %z',
47
- datetime_12_tzn: '%B %-d, %Y %I:%M %P %Z',
48
- datetime_12_abbr_tzn: '%b %-d, %Y %I:%M %P %Z',
49
- datetime_12_iso_tzn: '%Y-%m-%d %I:%M %P %z'
50
- }.freeze
51
- TIME_UNITS = {
52
- h: 'H',
53
- hour: 'H',
54
- hour_padded: 'H',
55
- hh: 'k',
56
- HOUR: 'k',
57
- hour_blank: 'k',
58
- hhh: 'I',
59
- hour_12: 'I',
60
- hour_12_padded: 'I',
61
- hhhh: 'l',
62
- HOUR_12: 'l',
63
- hour_12_blank: 'l',
64
- n: 'M',
65
- minute: 'M',
66
- s: 'S',
67
- second: 'S',
68
- ampm: 'P',
69
- meridian: 'P',
70
- AMPM: 'p',
71
- MERIDIAN: 'p',
72
- z: 'z',
73
- time_zone: 'z',
74
- zz: ':z',
75
- time_zone_offset: ':z',
76
- zzz: '::z',
77
- time_zone_offset_full: '::z',
78
- zzzz: 'Z',
79
- time_zone_name: 'Z'
80
- }.freeze
8
+ TIME_STAMPS ||= {
9
+ hour: '%H',
10
+ hour_blank: '%k',
11
+ hour_padded: '%H',
12
+ hour_12: '%I',
13
+ hour_12_padded: '%I',
14
+ hour_12_blank: '%l',
15
+ minute: '%M',
16
+ second: '%S',
17
+ ampm: '%P',
18
+ meridian: '%p',
19
+ time_zone: '%z',
20
+ time_zone_offset: '%:z',
21
+ time_zone_offset_full: '%::z',
22
+ time_zone_name: '%Z',
23
+ time: '%H:%M',
24
+ time_blank: '%k:%M',
25
+ time_padded: '%H:%M',
26
+ time_tz: '%H:%M %z',
27
+ time_tzn: '%H:%M %Z',
28
+ time_12: '%I:%M %P',
29
+ time_12_padded: '%I:%M %P',
30
+ time_12_blank: '%l:%M %P',
31
+ time_12_tz: '%I:%M %P %z',
32
+ time_12_tzn: '%I:%M %P %Z',
33
+ daytime: '%B %-d %H:%M',
34
+ daytime_abbr: '%b %-d %H:%M',
35
+ daytime_iso: '%m-%d %H:%M',
36
+ daytime_12: '%B %-d %I:%M %P',
37
+ daytime_12_abbr: '%b %-d %I:%M %P',
38
+ daytime_12_iso: '%m-%d %I:%M %P',
39
+ datetime: '%B %-d, %Y %H:%M',
40
+ datetime_abbr: '%b %-d, %Y %H:%M',
41
+ datetime_iso: '%Y-%m-%d %H:%M',
42
+ datetime_12: '%B %-d, %Y %I:%M %P',
43
+ datetime_12_abbr: '%b %-d, %Y %I:%M %P',
44
+ datetime_12_iso: '%Y-%m-%d %I:%M %P',
45
+ datetime_tzn: '%B %-d, %Y %H:%M %Z',
46
+ datetime_abbr_tzn: '%b %-d, %Y %H:%M %Z',
47
+ datetime_iso_tzn: '%Y-%m-%d %H:%M %z',
48
+ datetime_12_tzn: '%B %-d, %Y %I:%M %P %Z',
49
+ datetime_12_abbr_tzn: '%b %-d, %Y %I:%M %P %Z',
50
+ datetime_12_iso_tzn: '%Y-%m-%d %I:%M %P %z'
51
+ }.freeze
52
+ TIME_UNITS = {
53
+ h: 'H',
54
+ hour: 'H',
55
+ hour_padded: 'H',
56
+ hh: 'k',
57
+ HOUR: 'k',
58
+ hour_blank: 'k',
59
+ hhh: 'I',
60
+ hour_12: 'I',
61
+ hour_12_padded: 'I',
62
+ hhhh: 'l',
63
+ HOUR_12: 'l',
64
+ hour_12_blank: 'l',
65
+ n: 'M',
66
+ minute: 'M',
67
+ s: 'S',
68
+ second: 'S',
69
+ ampm: 'P',
70
+ meridian: 'P',
71
+ AMPM: 'p',
72
+ MERIDIAN: 'p',
73
+ z: 'z',
74
+ time_zone: 'z',
75
+ zz: ':z',
76
+ time_zone_offset: ':z',
77
+ zzz: '::z',
78
+ time_zone_offset_full: '::z',
79
+ zzzz: 'Z',
80
+ time_zone_name: 'Z'
81
+ }.freeze
81
82
 
83
+ end
82
84
  end
83
85
  end
84
86
  end
@@ -1,77 +1,79 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Integer
4
-
5
- ROMAN_NUMERALS ||= {
6
- M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4,
7
- I: 1
8
- }.freeze
3
+ if Lite::Ruby.configuration.monkey_patches.include?('integer')
4
+ class Integer
5
+
6
+ ROMAN_NUMERALS ||= {
7
+ M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4,
8
+ I: 1
9
+ }.freeze
10
+
11
+ def bit(bit)
12
+ if bit.negative?
13
+ mask = (1 << ~bit)
14
+ self & ~mask
15
+ else
16
+ mask = (1 << bit)
17
+ self | mask
18
+ end
19
+ end
9
20
 
10
- def bit(bit)
11
- if bit.negative?
12
- mask = (1 << ~bit)
13
- self & ~mask
14
- else
21
+ def bit?(bit)
15
22
  mask = (1 << bit)
16
- self | mask
23
+ (self & mask) != 0
17
24
  end
18
- end
19
-
20
- def bit?(bit)
21
- mask = (1 << bit)
22
- (self & mask) != 0
23
- end
24
25
 
25
- def bit_clear(bit)
26
- mask = (1 << bit)
27
- self & ~mask
28
- end
26
+ def bit_clear(bit)
27
+ mask = (1 << bit)
28
+ self & ~mask
29
+ end
29
30
 
30
- def bitmask(mask)
31
- if mask.negative?
32
- self & mask
33
- else
34
- self | mask
31
+ def bitmask(mask)
32
+ if mask.negative?
33
+ self & mask
34
+ else
35
+ self | mask
36
+ end
35
37
  end
36
- end
37
38
 
38
- def bitmask?(mask)
39
- (self & mask) != 0
40
- end
39
+ def bitmask?(mask)
40
+ (self & mask) != 0
41
+ end
41
42
 
42
- def factorial
43
- return 1 if zero?
43
+ def factorial
44
+ return 1 if zero?
44
45
 
45
- 2.upto(self).inject(1) { |acc, i| acc * i }
46
- end
46
+ 2.upto(self).inject(1) { |acc, i| acc * i }
47
+ end
47
48
 
48
- def factors
49
- limit = Math.sqrt(self).floor
49
+ def factors
50
+ limit = Math.sqrt(self).floor
50
51
 
51
- (1..limit).each_with_object([]) do |i, array|
52
- next unless (self % i).zero?
52
+ (1..limit).each_with_object([]) do |i, array|
53
+ next unless (self % i).zero?
53
54
 
54
- sq = (self / i)
55
- array.push(i)
56
- array.push(sq) if sq != i
55
+ sq = (self / i)
56
+ array.push(i)
57
+ array.push(sq) if sq != i
58
+ end
57
59
  end
58
- end
59
60
 
60
- def of(&block)
61
- Array.new(self, &block)
62
- end
61
+ def of(&block)
62
+ Array.new(self, &block)
63
+ end
63
64
 
64
- def roman_numeral
65
- return '' if zero?
66
- return "-#{(-self).roman_numeral}" if negative?
65
+ def roman_numeral
66
+ return '' if zero?
67
+ return "-#{(-self).roman_numeral}" if negative?
67
68
 
68
- ROMAN_NUMERALS.each { |key, val| break "#{key}#{(self - val).roman_numeral}" if val <= self }
69
- end
69
+ ROMAN_NUMERALS.each { |key, val| break "#{key}#{(self - val).roman_numeral}" if val <= self }
70
+ end
70
71
 
71
- def to_time
72
- Time.at(self)
73
- end
72
+ def to_time
73
+ Time.at(self)
74
+ end
74
75
 
75
- alias to_t to_time unless defined?(to_t)
76
+ alias to_t to_time unless defined?(to_t)
76
77
 
78
+ end
77
79
  end
@@ -1,29 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Kernel
3
+ if Lite::Ruby.configuration.monkey_patches.include?('kernel')
4
+ module Kernel
4
5
 
5
- # rubocop:disable Lint/RescueException, Security/Eval
6
- def safe_eval
7
- eval(self)
8
- rescue Exception
9
- self
10
- end
6
+ # rubocop:disable Lint/RescueException, Security/Eval
7
+ def safe_eval
8
+ eval(self)
9
+ rescue Exception
10
+ self
11
+ end
11
12
 
12
- def try_eval
13
- val = /\[\d*,?\d*,?\d*\]/.match(to_s).to_s
14
- return val if val.nil?
13
+ def try_eval
14
+ val = /\[\d*,?\d*,?\d*\]/.match(to_s).to_s
15
+ return val if val.nil?
15
16
 
16
- eval(val)
17
- end
18
- # rubocop:enable Lint/RescueException, Security/Eval
17
+ eval(val)
18
+ end
19
+ # rubocop:enable Lint/RescueException, Security/Eval
19
20
 
20
- private
21
+ private
21
22
 
22
- def caller_name(depth = 0)
23
- val = caller[depth][/`([^']*)'/, 1]
24
- return val if depth.zero? || !val.include?('<top (required)>')
23
+ def caller_name(depth = 0)
24
+ val = caller[depth][/`([^']*)'/, 1]
25
+ return val if depth.zero? || !val.include?('<top (required)>')
25
26
 
26
- caller[depth - 1][/`([^']*)'/, 1]
27
- end
27
+ caller[depth - 1][/`([^']*)'/, 1]
28
+ end
28
29
 
30
+ end
29
31
  end