Sha256: 3a00636ead8151b310a823c5d80e6ae4476c44a81ddb6186cb1a861329c0a6ec

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 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
  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

4 entries across 4 versions & 2 rubygems

Version Path
nori-1.0.3 lib/nori.rb
nori-1.0.2 lib/nori.rb
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/nori-1.0.1/lib/nori.rb
nori-1.0.1 lib/nori.rb