Class: YahooStock::Result::XmlFormat

Inherits:
YahooStock::Result show all
Defined in:
lib/yahoo_stock/result/xml_format.rb

Overview

DESCRIPTION:

Convert results to xml

USAGE

YahooStock::Result::XmlFormat.new(“data as string”)=> :values].output

Mostly will be used as a separate strategy for formatting results to xml

Instance Method Summary collapse

Methods inherited from YahooStock::Result

#store

Constructor Details

#initialize(data, &block) ⇒ XmlFormat

Returns a new instance of XmlFormat.



14
15
16
17
18
# File 'lib/yahoo_stock/result/xml_format.rb', line 14

def initialize(data, &block)
  @hash_format = YahooStock::Result::HashFormat.new(data){yield}
  @data = @hash_format.output
  super(self)
end

Instance Method Details

#outputObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yahoo_stock/result/xml_format.rb', line 20

def output
  builder = Builder::XmlMarkup.new(:indent=>2)
  builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  builder.items do |items|
    @data.each do |data|
      builder.item do |b|
        data.each_pair do |key, value|
          next if key.nil?
          eval("b.#{key}(value)")
        end
      end
    end
  end
  builder
end