Class: Euca::Wrapper
- Inherits:
-
Object
- Object
- Euca::Wrapper
- Defined in:
- lib/euca/wrapper.rb
Instance Method Summary collapse
-
#initialize(type_id, columns = nil) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #parse(response) ⇒ Object
- #run(api, *args) ⇒ Object
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
14 15 16 17 18 19 20 21 |
# File 'lib/euca/wrapper.rb', line 14 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 12 |
# File 'lib/euca/wrapper.rb', line 9 def run api, *args raise NoMethodError.new("Euca#run: #{api} not found") and return false unless Euca.api_methods.include?(api) parse Euca.sh(:"euca-#{api}", *args).to_s end |