rafini 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +117 -0
- data/lib/rafini.rb +10 -11
- data/lib/rafini/array.rb +2 -7
- data/lib/rafini/exception.rb +0 -1
- data/lib/rafini/hash.rb +0 -1
- data/lib/rafini/integer.rb +0 -1
- metadata +8 -13
- data/README.rdoc +0 -117
- data/lib/rafini/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b81e63f8b4651660cd62560692546173a7ae971ce0a0a76b6bc772c573f2d181
|
4
|
+
data.tar.gz: 37146803ff33ddcf74da2cd90bb5ddd4a2b1da0fe2be0c55b1b5b984a14029ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb3a3935d9892365a7568e304994605657b0ff0ed9c4e5adab0eee83c4d42d9584b0b6c6cdcd2d602f2817371d3a632f51396bf62b9ca134153c7eae926f22a
|
7
|
+
data.tar.gz: a1795c03155fbaa64fd90b4a5a8ab4ad033fa5489bb925168a765ab4be71b742cca5bc61d282c88c9c4af75c2b9c24feb8c2bd87f5d01189a5b32e34fd2a8c89
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# rafini 2.0.0
|
2
|
+
|
3
|
+
## DESCRIPTION:
|
4
|
+
|
5
|
+
Just a collection of useful refinements.
|
6
|
+
|
7
|
+
## SYNOPSIS:
|
8
|
+
|
9
|
+
### using Rafini::Array
|
10
|
+
|
11
|
+
# joins
|
12
|
+
['a','b','c','d','e','f'].joins('-','-',' '){':'} #=> "a-b-c d:e:f"
|
13
|
+
|
14
|
+
# per
|
15
|
+
h={}
|
16
|
+
['a','b','c'].per(['A','B','C']){|l,u| h[l]=u}
|
17
|
+
h #=> {'a'=>'A','b'=>'B','c'=>'C'}
|
18
|
+
|
19
|
+
# which
|
20
|
+
['dog','cat','bunny'].which{|a|a=~/c/} #=> "cat"
|
21
|
+
|
22
|
+
# is
|
23
|
+
[:a,:b,:c].is(true) #=> {a: true, b: true, c: true}
|
24
|
+
|
25
|
+
### using Rafini::Exception
|
26
|
+
|
27
|
+
# $!.puts
|
28
|
+
begin
|
29
|
+
raise 'Ugly Message'
|
30
|
+
rescue RuntimeError
|
31
|
+
$!.puts 'Nice Message'
|
32
|
+
end
|
33
|
+
|
34
|
+
# Rafini.bang!
|
35
|
+
value = Rafini.bang!('Nice Message') do
|
36
|
+
raise 'Ugly Message'
|
37
|
+
end
|
38
|
+
value #=> return value of block or error object
|
39
|
+
|
40
|
+
# Rafini.thread_bang!
|
41
|
+
Rafini.thread_bang!('Nice Message') do
|
42
|
+
# this is in a thread
|
43
|
+
raise 'Ugly Message'
|
44
|
+
end
|
45
|
+
|
46
|
+
### using Rafini::Hash
|
47
|
+
|
48
|
+
# to_struc
|
49
|
+
struct = {a:'A',b:'C',c:'C'}.to_struct
|
50
|
+
struct.a #=> 'A'
|
51
|
+
|
52
|
+
# modify
|
53
|
+
{a:'A',b:'B'}.modify({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X',c:'Y',d:'D'}
|
54
|
+
|
55
|
+
# supplement
|
56
|
+
{a:'A',b:'B'}.supplement({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'B',c:'C',d:'D'}
|
57
|
+
|
58
|
+
# amend
|
59
|
+
{a:'A',b:'B'}.amend({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X'}
|
60
|
+
|
61
|
+
# maps
|
62
|
+
{a:'A',b:'B',c:'C',c:'D'}.maps(:c,:a,:b) #=> ['C','A','B']
|
63
|
+
|
64
|
+
### using Rafini::Integer
|
65
|
+
|
66
|
+
# odometer
|
67
|
+
123.odometer(10,10) #=> [3,2,1]
|
68
|
+
30.odometer(2,3,5) #=> [0,0,0,1]
|
69
|
+
|
70
|
+
### using Rafini::Odometers
|
71
|
+
|
72
|
+
# sec2time
|
73
|
+
12501.sec2time.to_s #=> "3 hours and 28 minutes"
|
74
|
+
|
75
|
+
# illion
|
76
|
+
3_512_325.illion.to_s #=> "3.51M"
|
77
|
+
|
78
|
+
### using Rafini::String
|
79
|
+
|
80
|
+
# camelize
|
81
|
+
'a_camel_kick'.camelize #=> "ACamelKick"
|
82
|
+
|
83
|
+
# semantic
|
84
|
+
'1.2.3'.semantic(0..1) #=> '1.2'
|
85
|
+
|
86
|
+
### Rafini::Empty
|
87
|
+
|
88
|
+
STRING, ARRAY, HASH = ''.frozen, [].frozen, {}.frozen
|
89
|
+
|
90
|
+
## INSTALL:
|
91
|
+
|
92
|
+
$ gem install rafini
|
93
|
+
|
94
|
+
## LICENSE:
|
95
|
+
|
96
|
+
(The MIT License)
|
97
|
+
|
98
|
+
Copyright (c) 2020 carlosjhr64
|
99
|
+
|
100
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
101
|
+
a copy of this software and associated documentation files (the
|
102
|
+
'Software'), to deal in the Software without restriction, including
|
103
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
104
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
105
|
+
permit persons to whom the Software is furnished to do so, subject to
|
106
|
+
the following conditions:
|
107
|
+
|
108
|
+
The above copyright notice and this permission notice shall be
|
109
|
+
included in all copies or substantial portions of the Software.
|
110
|
+
|
111
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
112
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
113
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
114
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
115
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
116
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
117
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/rafini.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rafini/array'
|
4
|
-
require 'rafini/exception'
|
5
|
-
require 'rafini/hash'
|
6
|
-
require 'rafini/integer'
|
7
|
-
require 'rafini/string'
|
8
|
-
|
9
|
-
require 'rafini/
|
10
|
-
|
11
|
-
|
1
|
+
module Rafini
|
2
|
+
VERSION = '2.0.0'
|
3
|
+
require 'rafini/array'
|
4
|
+
require 'rafini/exception'
|
5
|
+
require 'rafini/hash'
|
6
|
+
require 'rafini/integer'
|
7
|
+
require 'rafini/string'
|
8
|
+
require 'rafini/odometers'
|
9
|
+
require 'rafini/empty'
|
10
|
+
end
|
12
11
|
# Requires:
|
13
12
|
#`ruby`
|
data/lib/rafini/array.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Rafini
|
2
2
|
module Array
|
3
3
|
refine ::Array do
|
4
|
-
|
5
4
|
# string = array.joins(sep1,sep2,sep3,...){|i| sep[i]}
|
6
5
|
#
|
7
6
|
# Returns a string created by converting each element of the array to
|
@@ -16,7 +15,7 @@ module Rafini
|
|
16
15
|
# ['a','b','c'].joins{|i|i} #=> 'a1b2c'
|
17
16
|
def joins(*p, &block)
|
18
17
|
str = ''
|
19
|
-
if length >
|
18
|
+
if length > 0
|
20
19
|
str << self[0]
|
21
20
|
1.upto(length-1) do |i|
|
22
21
|
str << (p.empty? ? (block ? block.call(i).to_s : '') : p.shift.to_s)
|
@@ -41,10 +40,7 @@ module Rafini
|
|
41
40
|
#
|
42
41
|
# Returns first object for which block is true.
|
43
42
|
# ['dog','cat','bunny'].which{|a|a=~/c/} #=> "cat"
|
44
|
-
|
45
|
-
self.each{|obj| return obj if yield(obj)}
|
46
|
-
return nil
|
47
|
-
end
|
43
|
+
alias which detect
|
48
44
|
|
49
45
|
# [:a,:b,:c].is(true) #=> {:a=>true,:b=>true,:c=>true}
|
50
46
|
#
|
@@ -53,7 +49,6 @@ module Rafini
|
|
53
49
|
self.each{|key| hash[key]=value}
|
54
50
|
return hash
|
55
51
|
end
|
56
|
-
|
57
52
|
end
|
58
53
|
end
|
59
54
|
end
|
data/lib/rafini/exception.rb
CHANGED
data/lib/rafini/hash.rb
CHANGED
data/lib/rafini/integer.rb
CHANGED
metadata
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rafini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Just a collection of useful refinements.
|
14
14
|
|
15
|
-
'
|
15
|
+
'
|
16
16
|
email: carlosjhr64@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
|
-
extra_rdoc_files:
|
20
|
-
- README.rdoc
|
19
|
+
extra_rdoc_files: []
|
21
20
|
files:
|
22
|
-
- README.
|
21
|
+
- README.md
|
23
22
|
- lib/rafini.rb
|
24
23
|
- lib/rafini/array.rb
|
25
24
|
- lib/rafini/empty.rb
|
@@ -28,15 +27,12 @@ files:
|
|
28
27
|
- lib/rafini/integer.rb
|
29
28
|
- lib/rafini/odometers.rb
|
30
29
|
- lib/rafini/string.rb
|
31
|
-
- lib/rafini/version.rb
|
32
30
|
homepage: https://github.com/carlosjhr64/rafini
|
33
31
|
licenses:
|
34
32
|
- MIT
|
35
33
|
metadata: {}
|
36
34
|
post_install_message:
|
37
|
-
rdoc_options:
|
38
|
-
- "--main"
|
39
|
-
- README.rdoc
|
35
|
+
rdoc_options: []
|
40
36
|
require_paths:
|
41
37
|
- lib
|
42
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -50,9 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
46
|
- !ruby/object:Gem::Version
|
51
47
|
version: '0'
|
52
48
|
requirements:
|
53
|
-
- 'ruby: ruby 2.
|
54
|
-
|
55
|
-
rubygems_version: 2.6.11
|
49
|
+
- 'ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]'
|
50
|
+
rubygems_version: 3.1.2
|
56
51
|
signing_key:
|
57
52
|
specification_version: 4
|
58
53
|
summary: Just a collection of useful refinements.
|
data/README.rdoc
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
= rafini
|
2
|
-
|
3
|
-
== DESCRIPTION:
|
4
|
-
|
5
|
-
Just a collection of useful refinements.
|
6
|
-
|
7
|
-
== SYNOPSIS:
|
8
|
-
|
9
|
-
=== using Rafini::Array
|
10
|
-
|
11
|
-
# joins
|
12
|
-
['a','b','c','d','e','f'].joins('-','-',' '){':'} #=> "a-b-c d:e:f"
|
13
|
-
|
14
|
-
# per
|
15
|
-
h={}
|
16
|
-
['a','b','c'].per(['A','B','C']){|l,u| h[l]=u}
|
17
|
-
h #=> {'a'=>'A','b'=>'B','c'=>'C'}
|
18
|
-
|
19
|
-
# which
|
20
|
-
['dog','cat','bunny'].which{|a|a=~/c/} #=> "cat"
|
21
|
-
|
22
|
-
# is
|
23
|
-
[:a,:b,:c].is(true) #=> {a: true, b: true, c: true}
|
24
|
-
|
25
|
-
=== using Rafini::Exception
|
26
|
-
|
27
|
-
# $!.puts
|
28
|
-
begin
|
29
|
-
raise 'Ugly Message'
|
30
|
-
rescue RuntimeError
|
31
|
-
$!.puts 'Nice Message'
|
32
|
-
end
|
33
|
-
|
34
|
-
# Rafini.bang!
|
35
|
-
value = Rafini.bang!('Nice Message') do
|
36
|
-
raise 'Ugly Message'
|
37
|
-
end
|
38
|
-
value #=> return value of block or error object
|
39
|
-
|
40
|
-
# Rafini.thread_bang!
|
41
|
-
Rafini.thread_bang!('Nice Message') do
|
42
|
-
# this is in a thread
|
43
|
-
raise 'Ugly Message'
|
44
|
-
end
|
45
|
-
|
46
|
-
=== using Rafini::Hash
|
47
|
-
|
48
|
-
# to_struc
|
49
|
-
struct = {a:'A',b:'C',c:'C'}.to_struct
|
50
|
-
struct.a #=> 'A'
|
51
|
-
|
52
|
-
# modify
|
53
|
-
{a:'A',b:'B'}.modify({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X',c:'Y',d:'D'}
|
54
|
-
|
55
|
-
# supplement
|
56
|
-
{a:'A',b:'B'}.supplement({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'B',c:'C',d:'D'}
|
57
|
-
|
58
|
-
# amend
|
59
|
-
{a:'A',b:'B'}.amend({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X'}
|
60
|
-
|
61
|
-
# maps
|
62
|
-
{a:'A',b:'B',c:'C',c:'D'}.maps(:c,:a,:b) #=> ['C','A','B']
|
63
|
-
|
64
|
-
=== using Rafini::Integer
|
65
|
-
|
66
|
-
# odometer
|
67
|
-
123.odometer(10,10) #=> [3,2,1]
|
68
|
-
30.odometer(2,3,5) #=> [0,0,0,1]
|
69
|
-
|
70
|
-
=== using Rafini::Odometers
|
71
|
-
|
72
|
-
# sec2time
|
73
|
-
12501.sec2time.to_s #=> "3 hours and 28 minutes"
|
74
|
-
|
75
|
-
# illion
|
76
|
-
3_512_325.illion.to_s #=> "3.51M"
|
77
|
-
|
78
|
-
=== using Rafini::String
|
79
|
-
|
80
|
-
# camelize
|
81
|
-
'a_camel_kick'.camelize #=> "ACamelKick"
|
82
|
-
|
83
|
-
# semantic
|
84
|
-
'1.2.3'.semantic(0..1) #=> '1.2'
|
85
|
-
|
86
|
-
=== Rafini::Empty
|
87
|
-
|
88
|
-
STRING, ARRAY, HASH = ''.frozen, [].frozen, {}.frozen
|
89
|
-
|
90
|
-
== INSTALL:
|
91
|
-
|
92
|
-
$ sudo gem install rafini
|
93
|
-
|
94
|
-
== LICENSE:
|
95
|
-
|
96
|
-
(The MIT License)
|
97
|
-
|
98
|
-
Copyright (c) 2017 carlosjhr64
|
99
|
-
|
100
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
101
|
-
a copy of this software and associated documentation files (the
|
102
|
-
'Software'), to deal in the Software without restriction, including
|
103
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
104
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
105
|
-
permit persons to whom the Software is furnished to do so, subject to
|
106
|
-
the following conditions:
|
107
|
-
|
108
|
-
The above copyright notice and this permission notice shall be
|
109
|
-
included in all copies or substantial portions of the Software.
|
110
|
-
|
111
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
112
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
113
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
114
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
115
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
116
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
117
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/rafini/version.rb
DELETED