class Saxerator::Configuration

Constants

ADAPTER_TYPES

Attributes

hash_key_generator[W]
output_type[R]

Public Class Methods

new() click to toggle source
# File lib/saxerator/configuration.rb, line 8
def initialize
  @adapter = :rexml
  @output_type = :hash
  @put_attributes_in_hash = false
  @ignore_namespaces = false
end

Public Instance Methods

adapter() click to toggle source
# File lib/saxerator/configuration.rb, line 22
def adapter
  require "saxerator/adapters/#{@adapter}"
  Saxerator::Adapters.const_get(@adapter.to_s.capitalize, false)
end
adapter=(name) click to toggle source
# File lib/saxerator/configuration.rb, line 15
def adapter=(name)
  unless ADAPTER_TYPES.include?(name)
    raise ArgumentError, "Unknown adapter '#{name.inspect}'"
  end
  @adapter = name
end
generate_key_for(val) click to toggle source
# File lib/saxerator/configuration.rb, line 37
def generate_key_for(val)
  hash_key_generator.call val
end
hash_key_generator() click to toggle source
# File lib/saxerator/configuration.rb, line 45
def hash_key_generator
  @hash_key_generator || hash_key_normalizer
end
hash_key_normalizer() click to toggle source
# File lib/saxerator/configuration.rb, line 41
def hash_key_normalizer
  @hash_key_normalizer ||= ->(x) { x.to_s }
end
ignore_namespaces!() click to toggle source
# File lib/saxerator/configuration.rb, line 66
def ignore_namespaces!
  @ignore_namespaces = true
end
ignore_namespaces?() click to toggle source
# File lib/saxerator/configuration.rb, line 62
def ignore_namespaces?
  @ignore_namespaces
end
output_type=(val) click to toggle source
# File lib/saxerator/configuration.rb, line 27
def output_type=(val)
  raise ArgumentError, "Unknown output_type '#{val.inspect}'" unless Builder.valid?(val)
  @output_type = val
  raise_error_if_using_put_attributes_in_hash_with_xml
end
put_attributes_in_hash!() click to toggle source
# File lib/saxerator/configuration.rb, line 70
def put_attributes_in_hash!
  @put_attributes_in_hash = true
  raise_error_if_using_put_attributes_in_hash_with_xml
end
put_attributes_in_hash?() click to toggle source
# File lib/saxerator/configuration.rb, line 75
def put_attributes_in_hash?
  @put_attributes_in_hash
end
raise_error_if_using_put_attributes_in_hash_with_xml() click to toggle source
# File lib/saxerator/configuration.rb, line 79
def raise_error_if_using_put_attributes_in_hash_with_xml
  if @output_type != :hash && @put_attributes_in_hash
    raise ArgumentError, "put_attributes_in_hash! is only valid \
                          when using output_type = :hash (the default)'"
  end
end
strip_namespaces!(*namespaces) click to toggle source
# File lib/saxerator/configuration.rb, line 53
def strip_namespaces!(*namespaces)
  if namespaces.any?
    matching_group = namespaces.join('|')
    @hash_key_normalizer = ->(x) { x.to_s.gsub(/(#{matching_group}):/, '') }
  else
    @hash_key_normalizer = ->(x) { x.to_s.gsub(/\w+:/, '') }
  end
end
symbolize_keys!() click to toggle source
# File lib/saxerator/configuration.rb, line 49
def symbolize_keys!
  @hash_key_generator = ->(x) { hash_key_normalizer.call(x).to_sym }
end