ruby_extended 1.1.0 → 1.1.1

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: 6713d9529df421372812b0a1d21c647eb6e4cbc2928d9d544ccfa1b4bef5ad0b
4
- data.tar.gz: 4400debd57858bbbbf006c2004ad6812c91baec26c1180a202f56bc5f5c9a8a5
3
+ metadata.gz: b7c41204675b7b3a94d582112a357dac467beedf9c80676be920b7a109ae4565
4
+ data.tar.gz: 30eaf7a00be8f1c9012d0bb44564f277c635018317b4d337dd7fc02a29e7b9f7
5
5
  SHA512:
6
- metadata.gz: 4766701ba03173a2ae2e07e88f0ff7ebe7e14bedf14ec78a5d622258f4c2b2521b8cdc790380e6b376050696ad60d1a2a27c700f1ee5a76c0fe4cc6396d669b5
7
- data.tar.gz: c8c9a8193876f82888c3163a4cc24469b396fc98e5c0002a09e2767d8f23b4ef036ec7cad87a284c68859a0d757bac5a85f31c63af3d11adfc4beea26c3433cc
6
+ metadata.gz: 04bbe145d55a90b769a6b4c48c9fc1869073a2dc3f5af2dd5955edf0c575e6792c694ff9dcabea50ce169c1e9c19d00fdcd8f828c7dd205d25a7c36a185c00f2
7
+ data.tar.gz: f59bed7c16106c93d5dd51d8f423793fdcda41ceb9085c1985d9fed1b1547737dbd319400752501feffe009ae8967bec29b14500aee88277d80747fa435d03f3
@@ -1,6 +1,25 @@
1
1
  # Ruby Extend - Array
2
2
 
3
3
 
4
+ <br/>
5
+
6
+
7
+ ### `.clean`
8
+ Cleans Array from empty values
9
+ ```ruby
10
+ ['', nil, 'value'].clean # => ['value']
11
+ ```
12
+ Allows to strip string values, before checking if it's empty, with parameter `strip`.
13
+ ```ruby
14
+ ['', nil, 'value', ' ', ' a '].clean(strip: true) # => ['value', ' a ']
15
+ ```
16
+ Note that strip, used in this method, is regular ruby `.strip` not
17
+ [.strip_whitespace](https://github.com/EdCordata-Ruby-Gems/ruby_extended/blob/master/documentation/string.md#strip_whitespace)
18
+ available in this gem.
19
+
20
+
21
+ <br/>
22
+
4
23
 
5
24
  ### `.sort_lv`
6
25
  Sorts Array respecting latvian characters, like `Ā`, `Č`, etc..
@@ -19,6 +38,9 @@ Method accepts block, so it can be used on hash arrays.
19
38
  ```
20
39
 
21
40
 
41
+ <br/>
42
+
43
+
22
44
  ### `.tabulate`
23
45
  Split and transpose array horizontally or vertically.
24
46
  ```ruby
@@ -59,6 +81,9 @@ Split and transpose array horizontally or vertically.
59
81
  ```
60
82
 
61
83
 
84
+ <br/>
85
+
86
+
62
87
  ### `.sample_index`
63
88
  Returns uniq array of hashes, based on one key.
64
89
  ```ruby
@@ -78,6 +103,9 @@ Returns original array if key not found
78
103
  ```
79
104
 
80
105
 
106
+ <br/>
107
+
108
+
81
109
  ### `.duplicates`
82
110
  Returns duplicates from array
83
111
  ```ruby
@@ -94,6 +122,9 @@ Returns duplicates from array with count
94
122
  ```
95
123
 
96
124
 
125
+ <br/>
126
+
127
+
97
128
  ### `.sum` (overwrites & extends existing method)
98
129
  ```ruby
99
130
  [1, 2, 3].sum # => 6
@@ -116,6 +147,9 @@ If the key is not found in any of the array hash items, will return `nil`
116
147
  ```
117
148
 
118
149
 
150
+ <br/>
151
+
152
+
119
153
  ### `.to_tree`
120
154
  Converts hash array with parent_id to embed array with children.
121
155
  ```ruby
@@ -1,6 +1,8 @@
1
1
  # Ruby Extend - Hash
2
2
 
3
3
 
4
+ <br/>
5
+
4
6
 
5
7
  ### `.deep_find`
6
8
  Returns key value in any hash level and return full path to it
@@ -1,6 +1,8 @@
1
1
  # Ruby Extend - Number (Integer, Float, BigDecimal, Complex, Rational)
2
2
 
3
3
 
4
+ <br/>
5
+
4
6
 
5
7
  ### `.no_zeros`
6
8
  Converts any number to string, that has no zeroes
@@ -10,6 +12,9 @@ Converts any number to string, that has no zeroes
10
12
  ```
11
13
 
12
14
 
15
+ <br/>
16
+
17
+
13
18
  ### `.to_money`
14
19
  Converts any number to string formatted in money format
15
20
  ```ruby
@@ -17,6 +22,9 @@ Converts any number to string formatted in money format
17
22
  ```
18
23
 
19
24
 
25
+ <br/>
26
+
27
+
20
28
  ### `.percent_of`
21
29
  Get percent value from number
22
30
  ```ruby
@@ -28,12 +36,15 @@ Possible to get decimal value as well
28
36
  ```
29
37
 
30
38
 
31
- ### `.get_percent_from`
32
- Get percent from two numbers
39
+ <br/>
40
+
41
+
42
+ ### `.percent_in`
43
+ Get how much, in percent, the first number fits inside second numbers
33
44
  ```ruby
34
- (2).get_percent_from(6) # => 33
45
+ (2).percent_in(6) # => 33
35
46
  ```
36
47
  Possible to get decimal value as well
37
48
  ```ruby
38
- (2).get_percent_from(6, decimal: true) # => 33.33333333333333
49
+ (2).percent_in(6, decimal: true) # => 33.33333333333333
39
50
  ```
@@ -1,6 +1,8 @@
1
1
  # Ruby Extend - Object (Array & Hash)
2
2
 
3
3
 
4
+ <br/>
5
+
4
6
 
5
7
  ### `.dig`
6
8
  Navigate hash or array without getting error, in case item is not found.
@@ -3,5 +3,5 @@
3
3
  * [Array](/documentation/array.md)
4
4
  * [Hash](/documentation/hash.md)
5
5
  * [Object](/documentation/object.md) (Array & Hash)
6
- * [Number](/documentation/object.md) (Integer, Float, BigDecimal, Complex, Rational)
6
+ * [Number](/documentation/number.md) (Integer, Float, BigDecimal, Complex, Rational)
7
7
  * [String](/documentation/string.md)
@@ -1,6 +1,8 @@
1
1
  # Ruby Extend - String
2
2
 
3
3
 
4
+ <br/>
5
+
4
6
 
5
7
  ### `.similarity_percent`
6
8
  Returns percentage on how similar are two strings
@@ -15,6 +17,9 @@ a.similarity_percent(b) # => 93.02325581395348
15
17
  ```
16
18
 
17
19
 
20
+ <br/>
21
+
22
+
18
23
  ### `.index_of`
19
24
  Return array of indexes found in string
20
25
  ```ruby
@@ -22,6 +27,9 @@ Return array of indexes found in string
22
27
  ```
23
28
 
24
29
 
30
+ <br/>
31
+
32
+
25
33
  ### `.strip_newline`
26
34
  Remove new line characters
27
35
  ```ruby
@@ -29,6 +37,9 @@ Remove new line characters
29
37
  ```
30
38
 
31
39
 
40
+ <br/>
41
+
42
+
32
43
  ### `.strip_whitespace`
33
44
  Remove multiple different whitespace characters
34
45
  ```ruby
@@ -38,9 +49,9 @@ Whitespace characters that are removed:
38
49
  <table border="1">
39
50
  <thead>
40
51
  <tr>
41
- <td>Name</td>
42
- <td>Code</td>
43
- </td>
52
+ <th>Name</th>
53
+ <th>Code</th>
54
+ </tr>
44
55
  </thead>
45
56
  <tbody>
46
57
  <tr>
@@ -2,6 +2,16 @@ class Array
2
2
  require 'unicode_utils'
3
3
 
4
4
 
5
+ def clean(strip: false)
6
+ self.map do |item|
7
+ next if item == ''
8
+ next if item.nil?
9
+ next if item.kind_of?(String) && strip && item.strip == ''
10
+ item
11
+ end.compact
12
+ end
13
+
14
+
5
15
  def sort_lv(&block)
6
16
  lang = [
7
17
  %w[e ē], %w[u ū], %w[i ī], %w[a ā], %w[s š], %w[g ģ], %w[k ķ], %w[l ļ],
@@ -17,7 +17,7 @@ module NumericRubyExtended
17
17
  options[:decimal] ? result : result.to_i
18
18
  end
19
19
 
20
- def get_percent_from(value, options = {})
20
+ def percent_in(value, options = {})
21
21
  result = (self.to_f / value.to_f * 100)
22
22
  options[:decimal] ? result : result.to_i
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module RubyExtended
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -6,6 +6,28 @@ require_relative '../lib/ruby_extended.rb'
6
6
  RSpec.describe Array do
7
7
 
8
8
 
9
+ describe 'Array.clean' do
10
+
11
+ it "Should clean nil's and empty strings" do
12
+ input_arr = ['', nil, 'value', ' ', ' a ']
13
+
14
+ expect(input_arr.clean.length).to eq(3)
15
+ expect(input_arr.clean.include?('value')).to(be_truthy)
16
+ expect(input_arr.clean.include?(' a ')).to(be_truthy)
17
+ expect(input_arr.clean.include?(' ')).to(be_truthy)
18
+ end
19
+
20
+ it 'Should check if string values are empty after strip, if strip is true' do
21
+ input_arr = ['', nil, 'value', ' ', ' a ']
22
+
23
+ expect(input_arr.clean(strip: true).length).to eq(2)
24
+ expect(input_arr.clean(strip: true).include?('value')).to(be_truthy)
25
+ expect(input_arr.clean(strip: true).include?(' a ')).to(be_truthy)
26
+ end
27
+
28
+ end
29
+
30
+
9
31
  describe 'Array.sort_lv' do
10
32
 
11
33
  it 'Should order Latvian special characters in array' do
@@ -184,7 +206,7 @@ RSpec.describe Array do
184
206
  end
185
207
 
186
208
  it 'Should return nil if hash key was not found' do
187
- expect( [ {a: 1}, {a: 'a'}, {a: 3} ].sum(key: :b) ).to be_nil
209
+ expect( [ {a: 1}, {a: 'a'}, {a: 3} ].sum(key: :b) ).to(be_nil)
188
210
  end
189
211
 
190
212
  end
@@ -86,26 +86,26 @@ RSpec.describe Numeric do
86
86
  end
87
87
 
88
88
 
89
- describe 'Numeric.get_percent_from' do
89
+ describe 'Numeric.percent_in' do
90
90
 
91
91
  it 'Should return percent from two numbers, using BigDecimal class' do
92
- expect(BigDecimal('1.0').get_percent_from(BigDecimal('2'))).to eql(50)
92
+ expect(BigDecimal('1.0').percent_in(BigDecimal('2'))).to eql(50)
93
93
  end
94
94
 
95
95
  it 'Should return percent from two numbers, using Float class' do
96
- expect(Float('1.0').get_percent_from(Float('2'))).to eql(50)
96
+ expect(Float('1.0').percent_in(Float('2'))).to eql(50)
97
97
  end
98
98
 
99
99
  it 'Should return percent from two numbers, using Integer class' do
100
- expect(Integer('1').get_percent_from(Integer('2'))).to eql(50)
100
+ expect(Integer('1').percent_in(Integer('2'))).to eql(50)
101
101
  end
102
102
 
103
103
  it 'Should return percent from two numbers, using Complex class' do
104
- expect(Complex('1.0').get_percent_from(Complex('2'))).to eql(50)
104
+ expect(Complex('1.0').percent_in(Complex('2'))).to eql(50)
105
105
  end
106
106
 
107
107
  it 'Should return percent from two numbers, using Rational class' do
108
- expect(Rational('1.0').get_percent_from(Rational('2'))).to eql(50)
108
+ expect(Rational('1.0').percent_in(Rational('2'))).to eql(50)
109
109
  end
110
110
 
111
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - EdCordata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-27 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_utils
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubygems_version: 3.1.2
84
+ rubygems_version: 3.1.4
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Extend Ruby classes with helpful methods