short_find 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/short_find.rb +100 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 75d8cf25c76a27380c8bae4a46552eb3fee389083ed3eac37b63b39955041924
|
4
|
+
data.tar.gz: ea893e04d03a929bac6c270657f3085f81265e9db16569e5a016fc85ac94d21e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de330e1d5b6e1322a4e075bb03ca8e55371b713c62c9f5a021159963faf93e2ed73f6ac843c2fa32bef1d47fc0c8d46e7c792764a21b12281022f1f0549d02c0
|
7
|
+
data.tar.gz: 0dce2243858719518a297aea8b9f502e7a1cb88f55d31f8bc8a102cbf2fa6e0b8f29dfb0a4191d8685d99071f1066c94bdfa92376f7e768b9a035678cc253dfb
|
data/lib/short_find.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
class ShortFind
|
2
|
+
@@back = false
|
3
|
+
@@exit = false
|
4
|
+
|
5
|
+
def self.use_back(boolean)
|
6
|
+
@@back = boolean
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.use_exit(boolean)
|
10
|
+
@@exit = boolean
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.outs(boolean)
|
14
|
+
@@back = boolean
|
15
|
+
@@exit = boolean
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.object(objects, attr=:name)
|
19
|
+
attr = attr.to_s
|
20
|
+
r_format = "first"
|
21
|
+
loop do
|
22
|
+
input = get_input
|
23
|
+
return if !input && @@back
|
24
|
+
|
25
|
+
result = objects.select do |object|
|
26
|
+
object.public_send(attr).downcase.gsub('ú', 'u').gsub(/[^a-z0-9]/,'').start_with?(input.downcase.gsub(/[^a-z0-9]/,''))
|
27
|
+
end
|
28
|
+
|
29
|
+
output = test_result(result, r_format, attr)
|
30
|
+
return output if output
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.in_array(array)
|
35
|
+
r_format = "first"
|
36
|
+
attr = "to_s"
|
37
|
+
loop do
|
38
|
+
input = get_input
|
39
|
+
return if !input && @@back
|
40
|
+
|
41
|
+
result = array.select do |element|
|
42
|
+
element.downcase.gsub('ú', 'u').gsub(/[^a-z0-9]/,'').start_with?(input.downcase.gsub(/[^a-z0-9]/,''))
|
43
|
+
end
|
44
|
+
|
45
|
+
output = test_result(result, r_format, attr)
|
46
|
+
return output if output
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.in_hash(hash, by=:value)
|
51
|
+
by = by.to_s
|
52
|
+
r_format = "to_h"
|
53
|
+
attr = "last"
|
54
|
+
loop do
|
55
|
+
input = get_input
|
56
|
+
return if !input && @@back
|
57
|
+
|
58
|
+
result = hash.select do |key, value|
|
59
|
+
if by == "key"
|
60
|
+
attr = "first"
|
61
|
+
key.to_s.downcase.gsub('ú', 'u').gsub(/[^a-z0-9]/,'').start_with?(input.downcase.gsub(/[^a-z0-9]/,''))
|
62
|
+
elsif by == "value"
|
63
|
+
value.downcase.gsub('ú', 'u').gsub(/[^a-z0-9]/,'').start_with?(input.downcase.gsub(/[^a-z0-9]/,''))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
output = test_result(result, r_format, attr)
|
68
|
+
return output if output
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def self.get_input
|
75
|
+
input = gets.strip
|
76
|
+
return if input == "back" && @@back
|
77
|
+
exit if input == "exit" && @@exit
|
78
|
+
input
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.test_result(result, r_format, attr)
|
82
|
+
if result.count == 0
|
83
|
+
puts ""
|
84
|
+
puts "No match found"
|
85
|
+
puts "Try again"
|
86
|
+
elsif result.count == 1
|
87
|
+
return result.public_send(r_format)
|
88
|
+
else
|
89
|
+
puts ""
|
90
|
+
puts "Multiple matches found"
|
91
|
+
puts ""
|
92
|
+
result.each do |result|
|
93
|
+
puts result.public_send(attr)
|
94
|
+
end
|
95
|
+
puts ""
|
96
|
+
puts "Try again"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: short_find
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arthur Torres
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Allow a user to find things by typing enough just letters and/or numbers
|
14
|
+
to make it unique. The user can enter a string of letters. Ignoring case, spaces,
|
15
|
+
and special characters, if thre is only one match, short_find will return the item
|
16
|
+
that starts with those characters. If no item is matched, or if more than one item
|
17
|
+
is matched it will give an error and allow the user to try again.
|
18
|
+
email: arthurtorres002@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/short_find.rb
|
24
|
+
homepage: http://rubygems.org/gems/short_find
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.7.8
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Allow a user to find things by typing enough just letters to make it unique.
|
48
|
+
test_files: []
|