Sha256: 41b10aa0e24c1156e26bb21abcc836a2946a787be69e21a5ad9ae571e54eee03

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

require "nori/version"
require "nori/core_ext"
require "nori/parser"
require "nori/xml_utility_node"

module Nori
  extend self

  # Translates the given +xml+ to a Hash. Accepts an optional +parser+ to use.
  def parse(xml, parser = nil)
    return {} if xml.blank?
    Parser.parse xml, parser, self
  end

  # Sets the +parser+ to use.
  def parser=(parser)
    Parser.use = parser
  end

  # Yields +self+ for configuration.
  def configure
    yield self
  end

  # Sets whether to use advanced typecasting.
  attr_writer :advanced_typecasting

  # Returns whether to use advanced typecasting.
  # Defaults to +true+.
  def advanced_typecasting?
    @advanced_typecasting != false
  end

  # Sets whether to strip namespaces.
  attr_writer :strip_namespaces

  # Returns whether to strip namespaces.
  # Defaults to +false+.
  def strip_namespaces?
    @strip_namespaces
  end

  # Expects a +block+ which receives a tag to convert.
  # Accepts +nil+ for a reset to the default behavior of not converting tags.
  def convert_tags_to(reset = nil, &block)
    @convert_tag = reset || block
  end

  # Transforms a given +tag+ using the specified conversion formula.
  def convert_tag(tag)
    @convert_tag.call(tag)
  end

  # Returns whether to convert tags.
  def convert_tags?
    @convert_tag
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/nori-1.1.5/lib/nori.rb
nori-1.1.5 lib/nori.rb
nori-1.1.4 lib/nori.rb
nori-1.1.3 lib/nori.rb
nori-1.1.2 lib/nori.rb
nori-1.1.0 lib/nori.rb