class OM::XML::Terminology::Builder
Terminology::Builder
Class Definition
When coding against Builders, remember that they rely on MethodMissing, so any time you call a method on the Builder
that it doesn't explicitly recognize, the Builder
will add your method & arguments to the it's settings and return itself.
Attributes
Public Class Methods
Create a new Terminology
Builder
object. options
are sent to the top level Document that is being built. (not yet supported:) root
can be a point in an existing Terminology
that you want to add Mappers into
Building a document with a particular encoding for example:
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| ... end
# File lib/om/xml/terminology.rb, line 36 def initialize(options = {}, root = nil, &block) @schema = options.fetch(:schema,nil) @namespaces = options.fetch(:namespaces,{}) @term_builders = {} @cur_term_builder = nil yield self if block_given? end
Public Instance Methods
# File lib/om/xml/terminology.rb, line 113 def build terminology = OM::XML::Terminology.new(:schema=>@schema, :namespaces=>@namespaces) root_term_builders.each do |root_term_builder| root_term_builder.children = self.term_builders.dup root_term_builder.children.delete(root_term_builder.name) end @term_builders.each_value do |root_builder| terminology.add_term root_builder.build(terminology) end terminology end
Add additional terms into this terminology
# File lib/om/xml/terminology.rb, line 109 def extend_terminology &block yield self if block_given? end
Returns the TermBuilder corresponding to the given pointer.
# File lib/om/xml/terminology.rb, line 93 def retrieve_term_builder(*args) args_cp = args.dup current_term = @term_builders[args_cp.delete_at(0)] if current_term.nil? raise OM::XML::Terminology::BadPointerError, "This TerminologyBuilder does not have a root TermBuilder defined that corresponds to \"#{args.first.inspect}\"" end args_cp.each do |arg| current_term = current_term.retrieve_child(arg) if current_term.nil? raise OM::XML::Terminology::BadPointerError, "You attempted to retrieve a TermBuilder using this pointer: #{args.inspect} but no TermBuilder exists at that location. Everything is fine until \"#{arg.inspect}\", which doesn't exist." end end return current_term end
Set the root of the Terminology
, along with namespace & schema info
# File lib/om/xml/terminology.rb, line 46 def root opts, &block @schema = opts.fetch(:schema,nil) opts.select {|k,v| k.to_s.include?("xmlns")}.each do |ns_pair| @namespaces[ns_pair.first.to_s] = ns_pair.last if ns_pair.first.to_s == "xmlns" @namespaces["oxns"] = ns_pair.last end end path = opts.fetch(:path,:root).to_s.sub(/[_!]$/, '') root_term_builder = OM::XML::Term::Builder.new(path).tap do |t| t.root_term= true end term_opts = opts.dup term_opts.delete(:schema) root_term_builder.settings.merge!(term_opts) @term_builders[root_term_builder.name] = root_term_builder return root_term_builder end
Returns an array of Terms that have been marked as “root” terms
# File lib/om/xml/terminology.rb, line 67 def root_term_builders @term_builders.values.select {|term_builder| term_builder.settings[:is_root_term] == true } end