class Pump::Xml

Constants

VALID_CHAR
VALID_XML_CHARS

Private Instance Methods

add_instruct?() click to toggle source
# File lib/pump/xml.rb, line 65
def add_instruct?
  encoder_options.has_key?(:instruct) ? encoder_options[:instruct] : true
end
build_tag(config, partial, path=[]) click to toggle source
# File lib/pump/xml.rb, line 41
def build_tag(config, partial, path=[])
  tag_name, method_name = config.keys.first, config.values.first
  attrs = config[:attributes]
  options = config.merge({:xml_key_style => encoder_options[:xml_key_style], :partial => partial, :path => path})
  if method_name.is_a?(Array)
    Tag.new(tag_name, attrs, method_name.map{|conf| build_tag(conf, partial, path.dup << tag_name) }, options)
  elsif config[:array]
    options.merge!(:array_method => method_name, :array_root => tag_name)
    child_root = config[:child_root] || tag_name.to_s.singularize
    tags = config[:array].map{|conf| build_tag(conf, partial, path.dup << tag_name) }
    TagArray.new(child_root, attrs, tags, options)
  else
    Tag.new(tag_name, attrs, Value.new(method_name), options)
  end
end
compile_string() click to toggle source
# File lib/pump/xml.rb, line 9
    def compile_string
      <<-EOV
        def to_structs(object, options)
          "#{Tag.new(root_name, {}, sub_tags, tag_options.merge(instruct: false))}"
        end

        def encode_single(object, options)
          "#{Tag.new(root_name, {}, sub_tags, tag_options)}"
        end

        def encode_array(objects, options)
          "#{TagArray.new(root_name, {}, sub_tags, tag_options)}"
        end

        def encode_partial_single(object, options)
          field_hash = options[:fields]
          "#{Tag.new(root_name, {}, sub_tags(true), tag_options)}"
        end

        def encode_partial_array(objects, options)
          field_hash = options[:fields]
          "#{TagArray.new(root_name, {}, sub_tags(true), tag_options)}"
        end
      EOV
    end
remove_ilegal_chars(string) click to toggle source
# File lib/pump/xml.rb, line 87
def remove_ilegal_chars(string)
  return string if !string.is_a?(String) || string =~ VALID_XML_CHARS
  out = ""
  string.chars.each do |c|
    case c.ord
    when *VALID_CHAR
      out << c
    end
  end
  out
end
sub_tags(partial=false) click to toggle source
# File lib/pump/xml.rb, line 35
def sub_tags(partial=false)
  encoder_config.map do |config|
    build_tag(config, partial)
  end
end
tag_options() click to toggle source
# File lib/pump/xml.rb, line 57
def tag_options
  {
    :instruct => add_instruct?, :extra_indent => encoder_options[:extra_indent],
    :array_root => encoder_options[:array_root],
    :xml_key_style => encoder_options[:xml_key_style]
  }
end