Class: Deltacloud::EC2::ResultParser

Inherits:
Object
  • Object
show all
Includes:
ResultHelper
Defined in:
lib/ec2/query_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResultHelper

#instance_state_code

Constructor Details

#initialize(query, object, context) ⇒ ResultParser

Returns a new instance of ResultParser.



104
105
106
107
108
# File 'lib/ec2/query_parser.rb', line 104

def initialize(query, object, context)
  @context = context
  @query = query
  @object = object
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



94
95
96
# File 'lib/ec2/query_parser.rb', line 94

def context
  @context
end

#objectObject (readonly)

Returns the value of attribute object.



93
94
95
# File 'lib/ec2/query_parser.rb', line 93

def object
  @object
end

#queryObject (readonly)

Returns the value of attribute query.



92
93
94
# File 'lib/ec2/query_parser.rb', line 92

def query
  @query
end

Class Method Details

.parse(query, result, context) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/ec2/query_parser.rb', line 96

def self.parse(query, result, context)
  parser = new(query, result, context)
  layout = "%#{query.action.to_s.camelize}Response{:xmlns => 'http://ec2.amazonaws.com/doc/2012-04-01/'}\n"+
    "\t%requestId #{query.request_id}\n" +
    "\t=render(:#{query.action}, object)\n"
  Haml::Engine.new(layout, :filename => 'layout').render(parser)
end

Instance Method Details

#build_xmlObject



110
111
112
# File 'lib/ec2/query_parser.rb', line 110

def build_xml
  Converter.convert(query.action, object)
end

#render(template, obj) ⇒ Object



114
115
116
117
# File 'lib/ec2/query_parser.rb', line 114

def render(template, obj)
  template_filename = File.join(File.dirname(__FILE__), 'views', '%s.haml' % template.to_s)
  Haml::Engine.new(File.read(template_filename), :filename => template_filename).render(self, :object => obj)
end