Class: Codewalk

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

Constant Summary collapse

BORDER =
"[= ]*"
DELIMITER =
/\n#{BORDER}EXAMPLE [0-9\.]*#{BORDER}\n/

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



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

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

#outputObject



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

def output()
    @chunks[-1]
end

#parse(output_raw) ⇒ Object



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

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



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

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

    self
end