class XsdModel::Parser

Public Class Methods

call(xml_string, options = {}) click to toggle source
# File lib/xsd_model/parser.rb, line 10
def self.call(xml_string, options = {})
  new(xml_string, options).call
end
new(xml_string, options) click to toggle source
# File lib/xsd_model/parser.rb, line 14
def initialize(xml_string, options)
  @xml = Nokogiri(xml_string)
  @options = options
end

Public Instance Methods

call() click to toggle source
# File lib/xsd_model/parser.rb, line 19
def call
  parse_node(@xml)
end

Private Instance Methods

collect_children(node) click to toggle source
# File lib/xsd_model/parser.rb, line 35
def collect_children(node)
  skippable, collectible = node.children.partition do |child|
    (@options[:collect_only] && !@options[:collect_only].call(child)) ||
      (@options[:ignore] && @options[:ignore].call(child))
  end

  collectible + skippable.flat_map { |child| collect_children(child) }
end
parse_node(node) click to toggle source
# File lib/xsd_model/parser.rb, line 25
def parse_node(node)
  klass = XsdModel::Elements.const_get node.name.camelize

  children = collect_children(node).map { |child| parse_node(child) }
  attributes = node.attributes.transform_values(&:value)
  namespaces = node.namespaces

  klass.new(children, attributes: attributes, namespaces: namespaces, css_path: node.css_path)
end