tooly 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tooly.rb +96 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e34c3a3a439710f402eeaa32e06fb25df2dd9aecca9976fc3a27225cb3a4f0d
|
4
|
+
data.tar.gz: a78eab7bcd9156ed9225cabda127dc48f63819f69081146f7434ed338e248513
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a23f86804d2a25ce4d1ef2a603fe61810a1c2efc2193b1a1e294fb71882c15af567e55ef029f5f841223423b2b3b2144f0f54fd5c675c4678af532eb6b46f15c
|
7
|
+
data.tar.gz: 34daf8d5a9a316d19746aab89dc279aa1c012c2807ae5d4bdf1dcb2a4684bda42b9436a1a70addd3615759700c446c58619e2cac4e6e5d5ee6c66ba5d1fb7488
|
data/lib/tooly.rb
CHANGED
@@ -1,6 +1,100 @@
|
|
1
|
+
require './lib/utils'
|
2
|
+
|
1
3
|
class Tooly
|
2
|
-
|
3
|
-
|
4
|
+
# Create a list without `null`, `false`, `0` and `''` from another list.
|
5
|
+
def self.compact(list)
|
6
|
+
listResult = []
|
7
|
+
if list.empty?
|
8
|
+
return listResult
|
9
|
+
end
|
10
|
+
for data in list do
|
11
|
+
unless data == nil || data == false || data == '' || data == 0
|
12
|
+
listResult << data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
return listResult
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create a list that contain the initial list and additional list
|
19
|
+
def self.concat(list, arg)
|
20
|
+
n = [list, arg]
|
4
21
|
return n.flatten!
|
5
22
|
end
|
23
|
+
|
24
|
+
# Create a list no duplicate elements from another list
|
25
|
+
def self.uniq(list)
|
26
|
+
list |= []
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create a string from a list
|
30
|
+
def self.listToString(list)
|
31
|
+
strFinal = ''
|
32
|
+
for e in list do
|
33
|
+
i = list.index(e)
|
34
|
+
if i < list.length() - 1
|
35
|
+
strFinal = "#{strFinal}#{list[i].to_s}, "
|
36
|
+
else
|
37
|
+
strFinal = strFinal + list[i].to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return strFinal
|
41
|
+
end
|
42
|
+
|
43
|
+
# Flattens list a single level deep
|
44
|
+
def self.flatten(list)
|
45
|
+
return list.flatten(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create an list of elements split into groups the length of initial list size.
|
49
|
+
def self.chunk(list, size)
|
50
|
+
result = []
|
51
|
+
aux = []
|
52
|
+
list.each_with_index do |item, i|
|
53
|
+
if (i + 1) % size == 0
|
54
|
+
aux << item
|
55
|
+
result << aux
|
56
|
+
aux = []
|
57
|
+
else
|
58
|
+
aux << item
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
unless aux.empty?
|
63
|
+
result.concat(aux)
|
64
|
+
end
|
65
|
+
return result
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create a list of values that not include in the second list.
|
69
|
+
def self.difference(fisrList, secondList)
|
70
|
+
result = []
|
71
|
+
for element in fisrList do
|
72
|
+
searchElement = secondList.find {|e| element == e }
|
73
|
+
|
74
|
+
if searchElement == nil
|
75
|
+
result << element
|
76
|
+
end
|
77
|
+
end
|
78
|
+
return result
|
79
|
+
end
|
80
|
+
|
81
|
+
# Create a list with `n` elements dropped from the beginning.
|
82
|
+
def self.drop(list, n)
|
83
|
+
length = list.length
|
84
|
+
if length == 0 || n > length
|
85
|
+
return []
|
86
|
+
else
|
87
|
+
return list.slice(n < 0 ? 0 : n, length)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Fills elements of `list` with `value` from `start` up to, but not including `end`.
|
92
|
+
def self.fill(list, value, st, en = nil)
|
93
|
+
length = list.length
|
94
|
+
if length == 0
|
95
|
+
return []
|
96
|
+
else
|
97
|
+
return Utils.baseFill(list, value, st, en)
|
98
|
+
end
|
99
|
+
end
|
6
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tooly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyGeek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Tooly is a package based in Lodash for Ruby
|
14
14
|
email:
|