Class: Euca::Wrapper

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

Instance Method Summary collapse

Constructor Details

#initialize(type_id, columns = nil) ⇒ Wrapper

Returns a new instance of Wrapper.



4
5
6
7
# File 'lib/euca/wrapper.rb', line 4

def initialize type_id, columns = nil
  @type_id = type_id
  @columns = columns
end

Instance Method Details

#parse(response) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/euca/wrapper.rb', line 13

def parse response
  response.split("\n").
  keep_if{ |line| line.match(/^#{@type_id}/i) }.
  map{ |line| 
    rows = line.gsub("\n","").split("\t")
    @columns.nil? ? rows : Hash[  @columns.zip( rows ) ]
  }
end

#run(api, *args) ⇒ Object



9
10
11
# File 'lib/euca/wrapper.rb', line 9

def run api, *args
  parse(sh("euca-#{api} #{args.join(" ")}"))
end