Class: Codewalk

Inherits:
Object
  • Object
show all
Defined in:
lib/codewalk.rb

Constant Summary collapse

DELIMITER =
/\nEXAMPLE [0-9]*\n/

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



18
19
20
# File 'lib/codewalk.rb', line 18

def [](index)
    @chunks[index]
end

#outputObject



22
23
24
# File 'lib/codewalk.rb', line 22

def output()
    @chunks[-1]
end

#parse(output_raw) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/codewalk.rb', line 5

def parse(output_raw)
    raw_chunks = output_raw.split(DELIMITER)
    raw_chunks.shift() # remove empty first element
    @chunks = raw_chunks.collect do |chunk|
        # remove starting and trailing newline from each chunk
        chunk[-1] = ""
        chunk[0] = ""
        chunk
    end

    self
end

#run(command) ⇒ Object



26
27
28
29
30
31
# File 'lib/codewalk.rb', line 26

def run(command)
    output_raw = `#{command}`
    parse(output_raw)

    self
end