rafini 0.5.0 → 2.0.0

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
- SHA1:
3
- metadata.gz: 487c2085e2d72ff8cbcb19139112d40803daaf94
4
- data.tar.gz: f367404c6323a01f3bd75b2cd69f2524e9ebd57d
2
+ SHA256:
3
+ metadata.gz: b81e63f8b4651660cd62560692546173a7ae971ce0a0a76b6bc772c573f2d181
4
+ data.tar.gz: 37146803ff33ddcf74da2cd90bb5ddd4a2b1da0fe2be0c55b1b5b984a14029ca
5
5
  SHA512:
6
- metadata.gz: c76b4db1a927a1a6b2ffd13f621adf32df2fb9657cf5f33e86bfa5d6457dc813f37d92d879009220c078574ad2807407e3233abf3e909d9c2706745a0fa8bcba
7
- data.tar.gz: 0d1f221119ff12ad9f978ae7f6c55c48c1f9a97009af8845d0637f6cc536902c903b2b01f63df318faed9eaf216306c93c3eed4a8842a486efb71041696f90d4
6
+ metadata.gz: ecb3a3935d9892365a7568e304994605657b0ff0ed9c4e5adab0eee83c4d42d9584b0b6c6cdcd2d602f2817371d3a632f51396bf62b9ca134153c7eae926f22a
7
+ data.tar.gz: a1795c03155fbaa64fd90b4a5a8ab4ad033fa5489bb925168a765ab4be71b742cca5bc61d282c88c9c4af75c2b9c24feb8c2bd87f5d01189a5b32e34fd2a8c89
@@ -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.
@@ -1,13 +1,12 @@
1
- require 'rafini/version'
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/odometers'
10
- require 'rafini/empty'
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`
@@ -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 > 1
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
- def which
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,17 +49,6 @@ module Rafini
53
49
  self.each{|key| hash[key]=value}
54
50
  return hash
55
51
  end
56
-
57
- # [:a, :b, :c].any?(:b, :d) #=> true
58
- #
59
- # Are any of the given in the array?
60
- def any?(*a)
61
- a.each do |b|
62
- return true if include?(b)
63
- end
64
- return false
65
- end
66
-
67
52
  end
68
53
  end
69
54
  end
@@ -1,7 +1,6 @@
1
1
  module Rafini
2
2
  module Exception
3
3
  refine ::Exception do
4
-
5
4
  # $!.puts outputs to standard error what went bang!
6
5
  # The given message is what you normally want to see.
7
6
  # The exeption message is also shown if in verbose mode.
@@ -1,7 +1,6 @@
1
1
  module Rafini
2
2
  module Hash
3
3
  refine ::Hash do
4
-
5
4
  # struct = hash.to_struct
6
5
  # Why not?
7
6
  def to_struct
@@ -52,9 +51,14 @@ module Rafini
52
51
  end
53
52
  self
54
53
  end
55
- # TODO: ammend was a typo, to go away on a major revision bump.
56
- alias ammend amend
57
54
 
55
+ # hash.maps(key1,...)
56
+ #
57
+ # Maps parameters list with hash.
58
+ # {a:'A",b:'B',c:'C'}.maps(:c,:a,:b) #=> ['C','A','B']
59
+ def maps(*keys)
60
+ keys.map{|_|self[_]}
61
+ end
58
62
  end
59
63
  end
60
64
  end
@@ -1,7 +1,6 @@
1
1
  module Rafini
2
2
  module Integer
3
3
  refine ::Integer do
4
-
5
4
  # odometer
6
5
  # Kinda hard to explain...
7
6
  # 123.odometer(10,10) #=> [3,2,1]
@@ -1,5 +1,44 @@
1
1
  module Rafini
2
2
  module Odometers
3
+ SEC2TIME = {
4
+ second: 60,
5
+ minute: 60,
6
+ hour: 24,
7
+ day: 7,
8
+ week: 4,
9
+ month: 13,
10
+ year: 10,
11
+ decade: 10,
12
+ centurie: 10,
13
+ millennium: 10,
14
+ age: 10,
15
+ epoch: 10,
16
+ era: 5,
17
+ eon: 2,
18
+ gigaannum: nil,
19
+ }
20
+
21
+ SCALE = {
22
+ base: {
23
+ ones: 10,
24
+ tens: 10,
25
+ hundreds: 10,
26
+ thousands: 1_000,
27
+ },
28
+ short: {
29
+ millions: 1_000,
30
+ billions: 1_000,
31
+ trillions: 1_000,
32
+ quadrillions: nil,
33
+ },
34
+ long: {
35
+ millions: 1_000_000,
36
+ billions: 1_000_000,
37
+ trillions: 1_000_000,
38
+ quadrillions: nil,
39
+ },
40
+ }
41
+
3
42
  refine ::Integer do
4
43
  # Need Rafini::Integer for #odometer
5
44
  # Need Rafini::Hash for #to_struct
@@ -27,24 +66,6 @@ module Rafini
27
66
  return hash.to_struct
28
67
  end
29
68
 
30
- SEC2TIME = {
31
- second: 60,
32
- minute: 60,
33
- hour: 24,
34
- day: 7,
35
- week: 4,
36
- month: 13,
37
- year: 10,
38
- decade: 10,
39
- centurie: 10,
40
- millennium: 10,
41
- age: 10,
42
- epoch: 10,
43
- era: 5,
44
- eon: 2,
45
- gigaannum: nil,
46
- }
47
-
48
69
  # Integer#sec2time
49
70
  # Returns a struct with the different time scales for number of seconds.
50
71
  # Note that the month(4 weeks)/year(13 months) are not meant to be exact.
@@ -54,27 +75,6 @@ module Rafini
54
75
  self.odoread(SEC2TIME)
55
76
  end
56
77
 
57
- SCALE = {
58
- base: {
59
- ones: 10,
60
- tens: 10,
61
- hundreds: 10,
62
- thousands: 1_000,
63
- },
64
- short: {
65
- millions: 1_000,
66
- billions: 1_000,
67
- trillions: 1_000,
68
- quadrillions: nil,
69
- },
70
- long: {
71
- millions: 1_000_000,
72
- billions: 1_000_000,
73
- trillions: 1_000_000,
74
- quadrillions: nil,
75
- },
76
- }
77
-
78
78
  # 1_230.illion.to_s #=> "1.23k"
79
79
  # 1_230_000.illion.to_s #=> "1.23M"
80
80
  # ...etc
@@ -5,7 +5,16 @@ module Rafini
5
5
  # 1) A camel kick, as in "I gotz camelized".
6
6
  # 2) "a_camel_kick" => "ACamelKick"
7
7
  def camelize(sep=/_/)
8
- self.split(sep).map{ |word| word.capitalize }.join('')
8
+ self.split(sep).map{|word|word.capitalize }.join('')
9
+ end
10
+
11
+ # semantic:
12
+ # 'a.b.c'.semantic(1) #=> 'b'
13
+ # 'a.b.c'.semantic(0..1) #=> 'a.b'
14
+ # 'a.b.c'.semantic(0..2, '/') #=> 'b/c'
15
+ # 'a/b/c'.semantic(0..2, '.', /\//) #=> 'a.b.c'
16
+ def semantic(v,s='.',sx=/\./)
17
+ [*self.split(sx)[v]].join(s)
9
18
  end
10
19
  end
11
20
  end
metadata CHANGED
@@ -1,24 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rafini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
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: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2020-08-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |
14
- Just a collection of useful refinements.
13
+ description: 'Just a collection of useful refinements.
14
+
15
+ '
15
16
  email: carlosjhr64@gmail.com
16
17
  executables: []
17
18
  extensions: []
18
- extra_rdoc_files:
19
- - README.rdoc
19
+ extra_rdoc_files: []
20
20
  files:
21
- - README.rdoc
21
+ - README.md
22
22
  - lib/rafini.rb
23
23
  - lib/rafini/array.rb
24
24
  - lib/rafini/empty.rb
@@ -27,15 +27,12 @@ files:
27
27
  - lib/rafini/integer.rb
28
28
  - lib/rafini/odometers.rb
29
29
  - lib/rafini/string.rb
30
- - lib/rafini/version.rb
31
30
  homepage: https://github.com/carlosjhr64/rafini
32
31
  licenses:
33
32
  - MIT
34
33
  metadata: {}
35
34
  post_install_message:
36
- rdoc_options:
37
- - "--main"
38
- - README.rdoc
35
+ rdoc_options: []
39
36
  require_paths:
40
37
  - lib
41
38
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -49,11 +46,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
46
  - !ruby/object:Gem::Version
50
47
  version: '0'
51
48
  requirements:
52
- - 'ruby: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]'
53
- rubyforge_project:
54
- rubygems_version: 2.4.1
49
+ - 'ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]'
50
+ rubygems_version: 3.1.2
55
51
  signing_key:
56
52
  specification_version: 4
57
53
  summary: Just a collection of useful refinements.
58
54
  test_files: []
59
- has_rdoc:
@@ -1,114 +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
- # any?
26
- [:a,:b,:c].any?(:b,:d) #=> true
27
-
28
- === using Rafini::Exception
29
-
30
- # $!.puts
31
- begin
32
- raise 'Ugly Message'
33
- rescue RuntimeError
34
- $!.puts 'Nice Message'
35
- end
36
-
37
- # Rafini.bang!
38
- value = Rafini.bang!('Nice Message') do
39
- raise 'Ugly Message'
40
- end
41
- value #=> return value of block or error object
42
-
43
- # Rafini.thread_bang!
44
- Rafini.thread_bang!('Nice Message') do
45
- # this is in a thread
46
- raise 'Ugly Message'
47
- end
48
-
49
- === using Rafini::Hash
50
-
51
- # to_struc
52
- struct = {a:'A',b:'C',c:'C'}.to_struct
53
- struct.a #=> 'A'
54
-
55
- # modify
56
- {a:'A',b:'B'}.modify({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X',c:'Y',d:'D'}
57
-
58
- # supplement
59
- {a:'A',b:'B'}.supplement({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'B',c:'C',d:'D'}
60
-
61
- # amend
62
- {a:'A',b:'B'}.amend({b:'X',c:'C'},{c:'Y',d:'D'}) #=> {a:'A',b:'X'}
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
- === Rafini::Empty
84
-
85
- STRING, ARRAY, HASH = ''.frozen, [].frozen, {}.frozen
86
-
87
- == INSTALL:
88
-
89
- $ sudo gem install rafini
90
-
91
- == LICENSE:
92
-
93
- (The MIT License)
94
-
95
- Copyright (c) 2014 carlosjhr64
96
-
97
- Permission is hereby granted, free of charge, to any person obtaining
98
- a copy of this software and associated documentation files (the
99
- 'Software'), to deal in the Software without restriction, including
100
- without limitation the rights to use, copy, modify, merge, publish,
101
- distribute, sublicense, and/or sell copies of the Software, and to
102
- permit persons to whom the Software is furnished to do so, subject to
103
- the following conditions:
104
-
105
- The above copyright notice and this permission notice shall be
106
- included in all copies or substantial portions of the Software.
107
-
108
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
109
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
110
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
111
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
112
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
113
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
114
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +0,0 @@
1
- module Rafini
2
- VERSION = '0.5.0'
3
- end