rafini 3.2.221213 → 3.3.230213

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: bdc3386e65af02b3a86031e7123e10391dc321de2b7559fb83e0639520db56a9
4
- data.tar.gz: 440f1bd45fee01d4ed81bbb536672367419e5cef35dc973277d3f12a950124d4
3
+ metadata.gz: 10beafcb6f8375979eba53ce6c8b1bfa75bf43caed120f1f9bc3c9a2275825a2
4
+ data.tar.gz: e5b55701451aed75917b02de376e8198b56466933fa17ac92e4e9672206496cd
5
5
  SHA512:
6
- metadata.gz: 29397cbfc1807873786d8770fd0b2fe5d2a1712492e1079cb568d6f39e8147abca80240cdd7f7885b16d2c90e4e453b7026cfcdc296ec921ee8bf17a9cd2b411
7
- data.tar.gz: ece7843e819e9c4745286f2f77052b9fbdd1a521d3f174fd8d652dd5d7d63650185a09410d457150fca8458f273965c9af6252f5883d56e3e33dcafc9fa8008b
6
+ metadata.gz: 12690de6469959ccbf5b7ad87c739045be1b025a06e94a2c6d585713def66d8c8820f2010d7011a6096abb6d29ab787be822d0576657786ac98ba62793fbcad6
7
+ data.tar.gz: 76c99a2f7fc92ac6c6a5e8f6bd192abf683c9267181d2ce033d7067f369b1504044effaa4b66f85d49caa2f1ca0d8ba0ef6cf60611768a2b733812e7e5f16f63
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rafini
2
2
 
3
- * [VERSION 3.2.221213](https://github.com/carlosjhr64/rafini/releases)
3
+ * [VERSION 3.3.230213](https://github.com/carlosjhr64/rafini/releases)
4
4
  * [github](https://github.com/carlosjhr64/rafini)
5
5
  * [rubygems](https://rubygems.org/gems/rafini)
6
6
 
@@ -67,12 +67,22 @@ using Rafini::Integer
67
67
  123.odometer(10,10) #=> [3, 2, 1]
68
68
  30.odometer(2,3,5) #=> [0, 0, 0, 1]
69
69
  ```
70
+ ### using Rafini::Object
71
+ ```ruby
72
+ using Rafini::Object
73
+
74
+ ''.as{_1.empty? ? :empty : _1.length} #=> :empty
75
+ '123'.as{_1.empty? ? :empty : _1.length} #=> 3
76
+ ```
70
77
  ### using Rafini::String
71
78
  ```ruby
72
79
  using Rafini::String
73
80
 
74
- # camelize
75
- 'a_camel_kick'.camelize #=> "ACamelKick"
81
+ # cases
82
+ 'My name is ruby'.pascal_case #=> MyNameIsRuby
83
+ 'My name is ruby'.camel_case #=> myNameIsRuby
84
+ 'My name is ruby'.snake_case #=> my_name_is_ruby
85
+ 'My name is ruby'.kebab_case #=> my-name-is-ruby
76
86
 
77
87
  # semantic
78
88
  '1.2.3'.semantic(0..1) #=> "1.2"
@@ -140,7 +150,7 @@ json ~>2.0' #=> ["json"]
140
150
 
141
151
  (The MIT License)
142
152
 
143
- Copyright (c) 2022 CarlosJHR64
153
+ Copyright (c) 2023 CarlosJHR64
144
154
 
145
155
  Permission is hereby granted, free of charge, to any person obtaining
146
156
  a copy of this software and associated documentation files (the
data/lib/rafini/array.rb CHANGED
@@ -4,9 +4,9 @@ module Rafini
4
4
  # classify:
5
5
  # Like Set#classify
6
6
  def classify(hash: ::Hash.new{|h,k|h[k]=[]}, &block)
7
- block ||= lambda{|v|v.class}
8
- self.each{|v| hash[block[v]] << v}
9
- return hash
7
+ block ||= ->(v){v.class}
8
+ each{|v| hash[block[v]] << v}
9
+ hash
10
10
  end
11
11
 
12
12
  # is:
@@ -15,7 +15,7 @@ module Rafini
15
15
  # Updates a hash with the keys given by the array to the given value.
16
16
  def is(value, hash={})
17
17
  each{|key| hash[key]=value}
18
- return hash
18
+ hash
19
19
  end
20
20
 
21
21
  # joins:
@@ -41,14 +41,14 @@ module Rafini
41
41
  string = ::String.new previous.to_s
42
42
  return string if items.empty?
43
43
  seps.flatten!
44
- while item = items.shift
45
- if sep = seps.shift&.to_s || block&.call(previous,item)&.to_s
44
+ while (item=items.shift)
45
+ if (sep=(seps.shift&.to_s || block&.call(previous,item)&.to_s))
46
46
  string << sep
47
47
  end
48
48
  string << item.to_s
49
49
  previous = item
50
50
  end
51
- return string
51
+ string
52
52
  end
53
53
  end
54
54
  end
@@ -11,11 +11,11 @@ module Rafini
11
11
  # # exact output depends on $VERBOSE and $DEBUG
12
12
  # $!.puts('Nice message')
13
13
  # end
14
- def puts(message=nil)
15
- unless $VERBOSE.nil? then
16
- $stderr.puts message if message
17
- $stderr.puts self.message if $VERBOSE or !message
18
- $stderr.puts self.backtrace.to_s if $DEBUG
14
+ def puts(msg=nil)
15
+ unless $VERBOSE.nil?
16
+ warn msg if msg
17
+ warn message if $VERBOSE || !msg
18
+ warn backtrace.to_s if $DEBUG
19
19
  end
20
20
  end
21
21
  end
@@ -29,14 +29,14 @@ using Rafini::Exception
29
29
  # value = Rafini.bang!('Ooops! Not perfect?') do
30
30
  # # Perfect code here...
31
31
  # end
32
- def Rafini.bang!(message=nil, bang=::Exception, &block)
33
- value = nil
32
+ def Rafini.bang!(msg=nil, bang=Exception, &block)
33
+ e = nil
34
34
  begin
35
- value = block.call
36
- rescue bang => value
37
- value.puts(message)
35
+ e = block.call
36
+ rescue bang => e
37
+ e.puts(msg)
38
38
  end
39
- return value
39
+ e
40
40
  end
41
41
 
42
42
  # The Thread wrapped version of bang!
@@ -52,6 +52,6 @@ end
52
52
  # end
53
53
  # With the following below, I'll be able to say
54
54
  # Rafini.thread_bang!('blah blah...'){ ...stuff... }
55
- def Rafini.thread_bang!(header=nil, bang=::Exception, &block)
56
- Thread.new{Rafini.bang!(header, bang, &block)}
55
+ def Rafini.thread_bang!(header=nil, bang=Exception, &)
56
+ Thread.new{Rafini.bang!(header, bang, &)}
57
57
  end
data/lib/rafini/hash.rb CHANGED
@@ -3,8 +3,8 @@ module Rafini
3
3
  refine ::Hash do
4
4
  # struct = hash.to_struct
5
5
  # Why not?
6
- def to_struct(&blk)
7
- Struct.new(*keys, &blk).new(*values)
6
+ def to_struct(&)
7
+ Struct.new(*keys, &).new(*values)
8
8
  end
9
9
 
10
10
  # hash0.supplement!(hash1,...) #=> hash
@@ -16,13 +16,13 @@ module Rafini
16
16
  def supplement!(*hashes)
17
17
  hashes.each do |hash|
18
18
  hash.each do |key, value|
19
- self[key] = value unless self.has_key?(key)
19
+ self[key] = value unless key?(key)
20
20
  end
21
21
  end
22
22
  self
23
23
  end
24
24
  def supplement(...)
25
- self.dup.supplement!(...)
25
+ dup.supplement!(...)
26
26
  end
27
27
 
28
28
  # hash0.amend(hash1,...)
@@ -32,13 +32,13 @@ module Rafini
32
32
  # only with first key value found in amending hashes.
33
33
  # {a:'A',b:'B'}.amend({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X'}
34
34
  def amend!(*hashes)
35
- self.each_key do |key|
36
- value=hashes.find{_1.has_key? key}&.fetch(key) and self[key]=value
35
+ each_key do |key|
36
+ value=hashes.find{_1.key? key}&.fetch(key) and self[key]=value
37
37
  end
38
38
  self
39
39
  end
40
40
  def amend(...)
41
- self.dup.amend!(...)
41
+ dup.amend!(...)
42
42
  end
43
43
  end
44
44
  end
@@ -9,7 +9,7 @@ module Rafini
9
9
  # #=> [30, 15, 12, 3]
10
10
  # Useful for making clocks, number scales, mayan long count... etc.
11
11
  def odometer(*levels, factors: true)
12
- raise RangeError, 'negative odometer' if self < 0
12
+ raise RangeError, 'negative odometer' if negative?
13
13
  readings, remainder = [], self
14
14
 
15
15
  levels = levels.inject([1]){|m, f| m.push(m.last*f)} if factors
@@ -0,0 +1,9 @@
1
+ module Rafini
2
+ module Object
3
+ refine ::Object do
4
+ def as
5
+ yield self
6
+ end
7
+ end
8
+ end
9
+ end
@@ -47,15 +47,15 @@ module Rafini
47
47
  def description
48
48
  string = ''
49
49
  reverse_each do |key, count|
50
- s = (count==1)? '' : 's'
50
+ s = count==1 ? '' : 's'
51
51
  unless string.empty?
52
- string << " and #{count} #{key}#{s}" if count > 0
52
+ string << " and #{count} #{key}#{s}" if count.positive?
53
53
  break
54
54
  end
55
- next if count == 0
55
+ next if count.zero?
56
56
  string << "#{count} #{key}#{s}"
57
57
  end
58
- return string
58
+ string
59
59
  end
60
60
  end
61
61
 
@@ -63,9 +63,9 @@ module Rafini
63
63
  using Rafini::Integer # Need Rafini::Integer for #odometer
64
64
  using Rafini::Hash # Need Rafini::Hash for #to_struct
65
65
 
66
- def odoread(scale, **kw, &blk)
66
+ def odoread(scale, **kw, &)
67
67
  counts = odometer(*scale.values, **kw)
68
- ::Hash[scale.keys.zip(counts)].to_struct(&blk)
68
+ scale.keys.zip(counts).to_h.to_struct(&)
69
69
  end
70
70
 
71
71
  # Integer#sec2time
@@ -73,23 +73,24 @@ module Rafini
73
73
  # 10_000.sec2time.to_s #=> "2 hours and 46 minutes"
74
74
  # 10_000.sec2time.hour #=> 2
75
75
  def sec2time
76
+ # Struct.new(*scale.keys).new(*counts){ method definitions }
76
77
  odoread(SEC2TIME, factors:false) do
77
78
  def to_s
78
79
  string = nil
79
80
  SEC2TIME.keys.reverse_each do |key|
80
81
  count=self[key]
81
82
  if string
82
- if count > 0
83
+ if count.positive?
83
84
  string << " and #{count} #{key}"
84
85
  string << 's' if count > 1
85
86
  end
86
87
  break
87
88
  end
88
- next if count==0
89
+ next if count.zero?
89
90
  string = "#{count} #{key}"
90
91
  string << 's' if count > 1
91
92
  end
92
- string = "0 #{SEC2TIME.first[0]}s" unless string
93
+ string ||= "0 #{SEC2TIME.first[0]}s"
93
94
  string
94
95
  end
95
96
  def to_i
@@ -126,16 +127,16 @@ module Rafini
126
127
  number = to_i
127
128
  return number.to_s if number < 1_000
128
129
  if number < 1_000_000
129
- precision = (number<10_000)? 2 : (number<100_000)? 1 : 0
130
+ precision = number<10_000 ? 2 : number<100_000 ? 1 : 0
130
131
  return "#{(number/1000.0).round(precision)}K"
131
132
  end
132
133
  keys = @scale.keys.reverse_each
133
134
  loop do
134
135
  key = keys.next
135
136
  n = self[key]
136
- next if n == 0
137
+ next if n.zero?
137
138
  if n < 1_000
138
- precision = (n<10)? 2 : (n<100)? 1 : 0
139
+ precision = n<10 ? 2 : n<100 ? 1 : 0
139
140
  scale = @scale[key].to_f
140
141
  f = (number/scale).round(precision)
141
142
  return "#{f}#{key[0].upcase}"
@@ -149,7 +150,7 @@ module Rafini
149
150
  end
150
151
  struct.type = type
151
152
  struct.scale = scale
152
- return struct
153
+ struct
153
154
  end
154
155
  end
155
156
  end
@@ -35,11 +35,11 @@ module Rafini
35
35
  require gemname and loaded.push gemname
36
36
  end
37
37
  end
38
- return loaded
38
+ loaded
39
39
  end
40
40
  end
41
41
  end
42
42
 
43
43
  using Requires
44
- def Rafini.requires(*list) = Kernel.requires(*list)
44
+ def self.requires(*list) = Kernel.requires(*list)
45
45
  end
data/lib/rafini/string.rb CHANGED
@@ -1,11 +1,33 @@
1
1
  module Rafini
2
2
  module String
3
3
  refine ::String do
4
+ def name_split
5
+ split(/[ _-]|(?=[A-Z])/)
6
+ end
7
+ # MyNameIsRuby
8
+ def pascal_case
9
+ name_split.map(&:capitalize).join
10
+ end
11
+ alias_method :title_case, :pascal_case
12
+ # myNameIsRuby
13
+ def camel_case
14
+ pascal_case.tap{_1[0]=_1[0].downcase}
15
+ end
16
+ # my_name_is_ruby
17
+ def snake_case(sep='_')
18
+ name_split.map(&:downcase).join(sep)
19
+ end
20
+ # my-name-is-ruby
21
+ def kebab_case
22
+ snake_case('-')
23
+ end
24
+
4
25
  # camelize:
5
26
  # 1) A camel kick, as in "I gotz camelized".
6
27
  # 2) "a_camel_kick" => "ACamelKick"
7
28
  def camelize(sep='_')
8
- self.split(sep).map(&:capitalize).join
29
+ warn 'DEPRECATED: use #pascal_case instead'
30
+ split(sep).map(&:capitalize).join
9
31
  end
10
32
 
11
33
  # semantic:
@@ -14,14 +36,14 @@ module Rafini
14
36
  # 'a.b.c'.semantic(0..2, join:'/') #=> 'b/c'
15
37
  # 'a/b/c'.semantic(0..2, split:'/', join:'.') #=> 'a.b.c'
16
38
  def semantic(v=(0..2), split:'.', join:'.')
17
- [*self.split(split)[v]].join(join)
39
+ [*split(split)[v]].join(join)
18
40
  end
19
41
 
20
42
  # shellescape:
21
43
  # Same funtionality as Shellword's String#shellescape
22
44
  def shellescape
23
45
  # This is a contraction of Shellwords.escape function
24
- self.gsub(/[^\w\-.,:+\/@\n]/,'\\\\\\&').gsub(/\n/,"'\n'")
46
+ gsub(/[^\w\-.,:+\/@\n]/,'\\\\\\&').gsub(/\n/,"'\n'")
25
47
  end
26
48
  end
27
49
  end
data/lib/rafini.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  module Rafini
2
- VERSION = '3.2.221213'
2
+ VERSION = '3.3.230213'
3
3
  # Constants
4
4
  autoload :Empty, 'rafini/empty'
5
5
  # Pure
6
6
  autoload :Array, 'rafini/array'
7
7
  autoload :Hash, 'rafini/hash'
8
8
  autoload :Integer, 'rafini/integer'
9
+ autoload :Object, 'rafini/object'
9
10
  autoload :String, 'rafini/string'
10
11
  # Hybrid
11
12
  autoload :Exception, 'rafini/exception'
metadata CHANGED
@@ -1,15 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rafini
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.221213
4
+ version: 3.3.230213
5
5
  platform: ruby
6
6
  authors:
7
7
  - CarlosJHR64
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-13 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: cucumber
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '8.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 8.0.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '8.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 8.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: help_parser
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '8.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 8.2.230210
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '8.2'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 8.2.230210
73
+ - !ruby/object:Gem::Dependency
74
+ name: parser
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.1
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.2.1
93
+ - !ruby/object:Gem::Dependency
94
+ name: rubocop
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.45'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.45.1
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.45'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.45.1
113
+ - !ruby/object:Gem::Dependency
114
+ name: stringio
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.0'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 3.0.5
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '3.0'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 3.0.5
133
+ - !ruby/object:Gem::Dependency
134
+ name: test-unit
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.5'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 3.5.7
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '3.5'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 3.5.7
13
153
  description: 'Just a collection of useful refinements.
14
154
 
15
155
  '
@@ -25,6 +165,7 @@ files:
25
165
  - lib/rafini/exception.rb
26
166
  - lib/rafini/hash.rb
27
167
  - lib/rafini/integer.rb
168
+ - lib/rafini/object.rb
28
169
  - lib/rafini/odometers.rb
29
170
  - lib/rafini/requires.rb
30
171
  - lib/rafini/string.rb
@@ -47,8 +188,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
188
  - !ruby/object:Gem::Version
48
189
  version: '0'
49
190
  requirements:
50
- - 'ruby: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]'
51
- rubygems_version: 3.3.7
191
+ - 'git: 2.30'
192
+ - 'ruby: 3.2'
193
+ rubygems_version: 3.4.6
52
194
  signing_key:
53
195
  specification_version: 4
54
196
  summary: Just a collection of useful refinements.