Class: Wirecard::Elastic::Request::Body::Builder::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/wirecard/elastic/request/body/builder/xml.rb

Constant Summary collapse

TEMPLATE_FORMAT =
"UTF-8".freeze
TEMPLATE_PATH =
"../../templates/".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_name, request) ⇒ Xml

template_name is contained in /templates/ the request matches the variables to convert (in hash) e.g. :refund



19
20
21
22
# File 'lib/wirecard/elastic/request/body/builder/xml.rb', line 19

def initialize(template_name, request)
  @template_name = template_name
  @request       = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



15
16
17
# File 'lib/wirecard/elastic/request/body/builder/xml.rb', line 15

def request
  @request
end

#template_nameObject (readonly)

Returns the value of attribute template_name.



15
16
17
# File 'lib/wirecard/elastic/request/body/builder/xml.rb', line 15

def template_name
  @template_name
end

Instance Method Details

#build!Object

actually convert the file into a full XML with processed variables



25
26
27
28
# File 'lib/wirecard/elastic/request/body/builder/xml.rb', line 25

def build!
  xml_template = File.open(template_path, "r:#{TEMPLATE_FORMAT}", &:read)
  xml_template.gsub(/{{\w+}}/, request_params)
end