Module: Commandorobo::Utils

Included in:
Commandorobo
Defined in:
lib/util.rb

Class Method Summary collapse

Class Method Details

.consume_switch(str) ⇒ Object

this function does not eat nintendo switches. do not try to feed it those.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/util.rb', line 10

def self.consume_switch(str) # this function does not eat nintendo switches. do not try to feed it those.
    nextarg = nil
    parsed = false
    switches = {}
    ws = str.split(' ')
    ws.each_with_index do |k, i|
        parsed = false
        if k.start_with?('-') && k.length > 1
            # oh heck a switch
            if k[1] == '-'
                # oh heck another switch
                k = self.nodash(k)
                switches[k.to_sym] = ws[i+1].nil? && !ws[i+1].start_with?('-') ? true : ws[i+1]
            else
                # no double-switch: interpret literally
                k = self.nodash(k)
                if k.length == 1
                    switches[k.to_sym] = ws[i+1].nil? && !ws[i+1].start_with?('-') ? true : ws[i+1]
                else
                    k.chars.each do |l|
                        switches[l.to_sym] = true
                    end
                    switches[switches.keys.last] = ws[i+1].nil? && !ws[i+1].start_with?('-') ? true : ws[i+1]
                end
            end
        end
    end
    return switches
end

.fish_xdm_login_hack_hack_hack_hackObject

I don’t know why this is here but it is, enjoy



40
41
42
# File 'lib/util.rb', line 40

def self. # I don't know why this is here but it is, enjoy
    'perry was here'
end

.nodash(i) ⇒ Object



6
7
8
# File 'lib/util.rb', line 6

def self.nodash(i)
    i.split('').reject {|j| j == '-'}.join('')
end

.remove_switch(str) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/util.rb', line 44

def self.remove_switch(str)
    parsed = []
    skip = false
    str.split(' ').each do |i|
        if skip
            skip = false
            next
        end
        if i.start_with?('-') && i.length > 1
            skip = true
        else
            parsed << i
        end
    end
    parsed
end