Class: YamWow::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, reference_data = nil) ⇒ Response

Returns a new instance of Response.



9
10
11
12
# File 'lib/yamwow/response.rb', line 9

def initialize(data, reference_data=nil)
  @data = data
  @reference_data = reference_data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/yamwow/response.rb', line 7

def data
  @data
end

#reference_dataObject

Returns the value of attribute reference_data.



7
8
9
# File 'lib/yamwow/response.rb', line 7

def reference_data
  @reference_data
end

Instance Method Details

#parse_template(template) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/yamwow/response.rb', line 18

def parse_template(template)
  keys = template.scan(/(\{(.+?)\})/m)
  results = flatten_data.map do |h|
    t = "#{template}"
    keys.each { |k| t.gsub! k[0], h[k[1]].to_s.gsub("\n", ' ') }
    t
  end
  results.join
end

#to_csv(options = {}) ⇒ Object



14
15
16
# File 'lib/yamwow/response.rb', line 14

def to_csv(options={})
  HashToCsv.to_csv @data, options
end