Sha256: 9a402ffa028e67e082c1365b8d18923cc47a87700ad7b31aabfcec880b40105a
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
require 'pump/xml/node' require 'active_support/core_ext/string/inflections' module Pump class Xml class TagArray < Node def initialize(name, attributes={}, nodes=[], options={}) tag = Tag.new(name, attributes, nodes, {:level => 1, :extra_indent => options[:extra_indent]}) array_root = options[:array_root] || name.to_s.pluralize super(array_root, {}, [tag], options) end def to_s if options.has_key?(:static_value) "#{prefix}<#{name} type=\\\"array\\\"#{static_value_and_close_tag}" else "#{prefix}<#{name} type=\\\"array\\\"#{loop_and_close_tag}" end end private def prefix options[:instruct] ? "#{Tag::INSTRUCT}" : tabs end def loop_and_close_tag "\#{ #{objects_path}.empty? ? \"/>\n\" : \">\n#{tag_loop}#{tabs}</#{name}>\n\" }" end def static_value_and_close_tag return "/>\n" if options[:static_value].nil? ">#{options[:static_value]}</#{name}>\n" end def objects_path options[:array_method] ? "object.#{options[:array_method]}" : "objects" end def tag_loop "\#{#{objects_path}.map{|object| \"#{nodes.first}\" }.join('')}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pump-0.6.0 | lib/pump/xml/tag_array.rb |
pump-0.5.1 | lib/pump/xml/tag_array.rb |