lite-ruby 1.3.3 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- if Lite::Ruby.configuration.monkey_patches.include?('struct')
4
- class Struct
3
+ class Struct
5
4
 
6
- def attributes
7
- each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
8
- end
9
-
10
- def replace(args)
11
- args.each_pair { |key, val| self[key] = val }
12
- end
5
+ def attributes
6
+ each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
7
+ end
13
8
 
9
+ def replace(args)
10
+ args.each_pair { |key, val| self[key] = val }
14
11
  end
12
+
15
13
  end
@@ -1,46 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if Lite::Ruby.configuration.monkey_patches.include?('time')
4
- class Time
3
+ require 'yaml' unless defined?(YAML)
5
4
 
6
- include Lite::Ruby::DateHelper
7
- include Lite::Ruby::TimeHelper
5
+ require 'lite/ruby/helpers/date_time_helper' unless defined?(Lite::Ruby::DateTimeHelper)
8
6
 
9
- class << self
7
+ class Time
10
8
 
11
- def elapse(verbose: false)
12
- started_at = monotonic
13
- yield
14
- ended_at = monotonic
15
- runtime = ended_at - started_at
16
- return runtime unless verbose
9
+ include Lite::Ruby::DateTimeHelper
17
10
 
18
- { started_at: started_at, ended_at: ended_at, runtime: runtime }
19
- end
11
+ DEFAULT_STAMP = 'datetime_iso'
12
+ DEFAULT_UNIT = 'year-month-day hour:minute'
20
13
 
21
- def monotonic
22
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
23
- end
14
+ STAMPS =
15
+ YAML.load_file(File.expand_path('formats/time_stamps.yml', File.dirname(__FILE__))).merge(
16
+ YAML.load_file(File.expand_path('formats/date_stamps.yml', File.dirname(__FILE__)))
17
+ ).freeze
18
+ UNITS =
19
+ YAML.load_file(File.expand_path('formats/time_units.yml', File.dirname(__FILE__))).merge(
20
+ YAML.load_file(File.expand_path('formats/date_units.yml', File.dirname(__FILE__)))
21
+ ).freeze
24
22
 
25
- end
26
-
27
- private
28
-
29
- def default_format
30
- 'year-month-day hour:minute'
31
- end
23
+ class << self
32
24
 
33
- def default_stamp
34
- :datetime_iso
35
- end
25
+ def elapse(verbose: false)
26
+ started_at = monotonic
27
+ yield
28
+ ended_at = monotonic
29
+ runtime = ended_at - started_at
30
+ return runtime unless verbose
36
31
 
37
- def format_for(key)
38
- TIME_UNITS[key] || DATE_UNITS[key]
32
+ { started_at: started_at, ended_at: ended_at, runtime: runtime }
39
33
  end
40
34
 
41
- def stamp_for(key)
42
- TIME_STAMPS[key] || DATE_STAMPS[key]
35
+ def monotonic
36
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
43
37
  end
44
38
 
45
39
  end
40
+
46
41
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION = '1.3.3'
6
+ VERSION = '2.0.3'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -180,14 +180,19 @@ files:
180
180
  - lib/lite/ruby.rb
181
181
  - lib/lite/ruby/array.rb
182
182
  - lib/lite/ruby/boolean.rb
183
- - lib/lite/ruby/configuration.rb
184
183
  - lib/lite/ruby/date.rb
185
184
  - lib/lite/ruby/enumerable.rb
185
+ - lib/lite/ruby/formats/date_stamps.yml
186
+ - lib/lite/ruby/formats/date_units.yml
187
+ - lib/lite/ruby/formats/integer_roman_numerals.yml
188
+ - lib/lite/ruby/formats/string_transliterations.yml
189
+ - lib/lite/ruby/formats/time_stamps.yml
190
+ - lib/lite/ruby/formats/time_units.yml
186
191
  - lib/lite/ruby/hash.rb
187
- - lib/lite/ruby/helpers/date_helper.rb
188
- - lib/lite/ruby/helpers/time_helper.rb
192
+ - lib/lite/ruby/helpers/date_time_helper.rb
189
193
  - lib/lite/ruby/integer.rb
190
194
  - lib/lite/ruby/kernel.rb
195
+ - lib/lite/ruby/monkey_patches.rb
191
196
  - lib/lite/ruby/numeric.rb
192
197
  - lib/lite/ruby/object.rb
193
198
  - lib/lite/ruby/open_struct.rb
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Ruby
5
-
6
- class Configuration
7
-
8
- attr_accessor :monkey_patches
9
-
10
- def initialize
11
- @monkey_patches = %w[
12
- array boolean date enumerable hash integer kernel numeric object open_struct range string
13
- struct time
14
- ]
15
- end
16
-
17
- end
18
-
19
- class << self
20
-
21
- attr_writer :configuration
22
-
23
- def configuration
24
- @configuration ||= Configuration.new
25
- end
26
-
27
- def configure
28
- yield(configuration)
29
- end
30
-
31
- def reset_configuration!
32
- @configuration = Configuration.new
33
- end
34
-
35
- end
36
-
37
- end
38
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if Lite::Ruby.configuration.monkey_patches.include?('date')
4
- module Lite
5
- module Ruby
6
- module DateHelper
7
-
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
88
-
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
96
-
97
- def stamp(key = nil)
98
- key = stamp_for(key&.to_sym || default_stamp)
99
- strftime(key)
100
- end
101
-
102
- alias to_format stamp
103
-
104
- end
105
- end
106
- end
107
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if Lite::Ruby.configuration.monkey_patches.include?('time')
4
- module Lite
5
- module Ruby
6
- module TimeHelper
7
-
8
- TIME_STAMPS = {
9
- hour: '%H',
10
- hour_blank: '%k',
11
- hour_padded: '%H',
12
- hour12: '%I',
13
- hour12_padded: '%I',
14
- hour12_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
- time12: '%I:%M %P',
29
- time12_padded: '%I:%M %P',
30
- time12_blank: '%l:%M %P',
31
- time12_tz: '%I:%M %P %z',
32
- time12_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
- daytime12: '%B %-d %I:%M %P',
37
- daytime12_abbr: '%b %-d %I:%M %P',
38
- daytime12_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
- datetime12: '%B %-d, %Y %I:%M %P',
43
- datetime12_abbr: '%b %-d, %Y %I:%M %P',
44
- datetime12_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
- datetime12_tzn: '%B %-d, %Y %I:%M %P %Z',
49
- datetime12_abbr_tzn: '%b %-d, %Y %I:%M %P %Z',
50
- datetime12_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
- hour12: 'I',
61
- hour12_padded: 'I',
62
- hhhh: 'l',
63
- HOUR12: 'l',
64
- hour12_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
82
-
83
- end
84
- end
85
- end
86
- end