glib 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/glib.rb +99 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abbb733d5e5669851b78381f898028c292ff806a
|
4
|
+
data.tar.gz: 896e51633e1943c96484a4068f3c14f5187c8f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4673c9d60b3764b6c1fe51a893c65e41c2fa394566141484fec9014587118962a1a966bf1daa111a338cc2fcb73117d1c4cdf0d94c6eda73a7aec420c6052be
|
7
|
+
data.tar.gz: c26bcf5eb5c97a4917ee51e1d48d789c9098be4e3095cdc5abc92246f2ecf2b76f5eba03bb720e2ca02deefc5871a98029adcffa227ea6667ad73b712ed9ab7b
|
data/lib/glib.rb
CHANGED
@@ -1,31 +1,16 @@
|
|
1
1
|
module Glib
|
2
|
-
def self.shift(array, index)
|
3
|
-
if not array.kind_of?(Array) then raise TypeError, "expected: Array" end
|
4
|
-
array.delete_at(index)
|
5
|
-
newarray = []
|
6
|
-
for i in 0..array.length - 1
|
7
|
-
if array[i] != nil
|
8
|
-
newarray.push(array[i])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
return newarray
|
12
|
-
end
|
13
2
|
def self.isodd?(input)
|
14
|
-
|
15
|
-
return true
|
16
|
-
else
|
17
|
-
return false
|
18
|
-
end
|
3
|
+
return input % 2 != 0
|
19
4
|
end
|
5
|
+
|
6
|
+
|
20
7
|
def self.iseven?(input)
|
21
|
-
|
22
|
-
return true
|
23
|
-
else
|
24
|
-
return false
|
25
|
-
end
|
8
|
+
return input % 2 == 0
|
26
9
|
end
|
10
|
+
|
11
|
+
|
27
12
|
def self.greatest(array)
|
28
|
-
if not array.kind_of?(Array) then raise TypeError
|
13
|
+
if not array.kind_of?(Array) then raise TypeError end
|
29
14
|
greatest_index = 0
|
30
15
|
for i in 0..array.length - 1
|
31
16
|
if array[i] > array[greatest_index]
|
@@ -34,8 +19,10 @@ module Glib
|
|
34
19
|
end
|
35
20
|
return greatest_index
|
36
21
|
end
|
22
|
+
|
23
|
+
|
37
24
|
def self.smallest(array)
|
38
|
-
if not array.kind_of?(Array) then raise TypeError
|
25
|
+
if not array.kind_of?(Array) then raise TypeError end
|
39
26
|
smallest_index = 0
|
40
27
|
for i in 1..array.length - 1
|
41
28
|
if array[i] < array[smallest_index]
|
@@ -44,12 +31,99 @@ module Glib
|
|
44
31
|
end
|
45
32
|
return smallest_index
|
46
33
|
end
|
47
|
-
|
48
|
-
|
34
|
+
|
35
|
+
|
36
|
+
def self.normalize(array, char = ",")
|
37
|
+
if not array.kind_of?(Array) then raise TypeError end
|
49
38
|
concat = ""
|
50
39
|
for i in 0..array.length - 1
|
51
40
|
concat = concat + array[i] + char
|
52
41
|
end
|
53
42
|
return concat[0..-2]
|
54
43
|
end
|
44
|
+
|
45
|
+
def self.readconfig(path)
|
46
|
+
if not File.exist?(path) then raise NoMethodError end
|
47
|
+
lines = File.readlines(path)
|
48
|
+
config = {}
|
49
|
+
lines.each do |line|
|
50
|
+
key, value = line.split(": ")
|
51
|
+
config.merge({key => value})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.tableprint(array)
|
56
|
+
if not array.kind_of?(Array) then raise TypeError end
|
57
|
+
long = 0
|
58
|
+
for i in 0..array.length - 1
|
59
|
+
for j in 0..array[i].length - 1
|
60
|
+
if array[i][j].to_s.length > long
|
61
|
+
long = array[i][j].to_s.length
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
for i in 0..array.length - 1
|
67
|
+
for j in 0..array[i].length - 1
|
68
|
+
spaces = " "
|
69
|
+
for k in 1..long - array[i][j].to_s.length
|
70
|
+
spaces = spaces + " "
|
71
|
+
end
|
72
|
+
print array[i][j].to_s + spaces
|
73
|
+
end
|
74
|
+
puts ""
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Array
|
80
|
+
def tableprint()
|
81
|
+
long = 0
|
82
|
+
for i in 0..self.length - 1
|
83
|
+
for j in 0..self[i].length - 1
|
84
|
+
if self[i][j].to_s.length > long
|
85
|
+
long = self[i][j].to_s.length
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
for i in 0..self.length - 1
|
91
|
+
for j in 0..self[i].length - 1
|
92
|
+
spaces = " "
|
93
|
+
for k in 1..long - self[i][j].to_s.length
|
94
|
+
spaces = spaces + " "
|
95
|
+
end
|
96
|
+
print self[i][j].to_s + spaces
|
97
|
+
end
|
98
|
+
puts ""
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def normalize(char = ",")
|
103
|
+
concat = ""
|
104
|
+
for i in 0..self.length - 1
|
105
|
+
concat = concat + self[i] + char
|
106
|
+
end
|
107
|
+
return concat[0..-2]
|
108
|
+
end
|
109
|
+
|
110
|
+
def smallest()
|
111
|
+
smallest_index = 0
|
112
|
+
for i in 1..self.length - 1
|
113
|
+
if self[i] < self[smallest_index]
|
114
|
+
smallest_index = i
|
115
|
+
end
|
116
|
+
end
|
117
|
+
return smallest_index
|
118
|
+
end
|
119
|
+
|
120
|
+
def greatest()
|
121
|
+
greatest_index = 0
|
122
|
+
for i in 0..self.length - 1
|
123
|
+
if self[i] > self[greatest_index]
|
124
|
+
greatest_index = i
|
125
|
+
end
|
126
|
+
end
|
127
|
+
return greatest_index
|
128
|
+
end
|
55
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Vian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Testing gem
|
14
14
|
email: casa@gabrielvian.it
|
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
39
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.6.
|
40
|
+
rubygems_version: 2.6.13
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Completely useless
|