Class: OM::XML::Term
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Term Class Definition.
-
#children ⇒ Object
Returns the value of attribute children.
-
#data_type ⇒ Object
Term Class Definition.
-
#default_content_path ⇒ Object
Term Class Definition.
-
#index_as ⇒ Object
Term Class Definition.
-
#internal_xml ⇒ Object
Returns the value of attribute internal_xml.
-
#is_root_term ⇒ Object
Term Class Definition.
-
#name ⇒ Object
Term Class Definition.
-
#namespace_prefix ⇒ Object
Term Class Definition.
-
#path ⇒ Object
Term Class Definition.
-
#required ⇒ Object
Term Class Definition.
-
#terminology ⇒ Object
Returns the value of attribute terminology.
-
#variant_of ⇒ Object
Term Class Definition.
-
#xpath ⇒ Object
Term Class Definition.
-
#xpath_constrained ⇒ Object
Term Class Definition.
-
#xpath_relative ⇒ Object
Term Class Definition.
Attributes included from TreeNode
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_xpath_queries! ⇒ Object
Generates absolute, relative, and constrained xpaths for the term, setting xpath, xpath_relative, and xpath_constrained accordingly.
-
#initialize(name, opts = {}) ⇒ Term
constructor
h2.
- #is_root_term? ⇒ Boolean
-
#retrieve_term(*pointers) ⇒ Object
crawl down into mapper’s children hash to find the desired mapper ie.
-
#xml_builder_template(extra_opts = {}) ⇒ Object
term_pointers
reference to the property you want to generate a builder template for. - #xpath_absolute ⇒ Object
Methods included from TreeNode
#add_child, #parent, #retrieve_child, #set_parent
Constructor Details
#initialize(name, opts = {}) ⇒ Term
h2. Namespaces By default, OM assumes that all terms in a Terminology have the namespace set in the root of the document. If you want to set a different namespace for a Term, pass :namespasce_prefix into its initializer (or call .namespace_prefix= on its builder) If a node has no namespace, you must explicitly set namespace_prefix to nil.
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/om/xml/term.rb', line 135 def initialize(name, opts={}) opts = {:namespace_prefix=>"oxns", :ancestors=>[], :children=>{}}.merge(opts) [:children, :ancestors,:path, :index_as, :required, :type, :variant_of, :path, :attributes, :default_content_path, :namespace_prefix].each do |accessor_name| instance_variable_set("@#{accessor_name}", opts.fetch(accessor_name, nil) ) end @name = name if @path.nil? || @path.empty? @path = name.to_s end end |
Instance Attribute Details
#attributes ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
128 129 130 |
# File 'lib/om/xml/term.rb', line 128 def children @children end |
#data_type ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def data_type @data_type end |
#default_content_path ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def default_content_path @default_content_path end |
#index_as ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def index_as @index_as end |
#internal_xml ⇒ Object
Returns the value of attribute internal_xml.
128 129 130 |
# File 'lib/om/xml/term.rb', line 128 def internal_xml @internal_xml end |
#is_root_term ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def is_root_term @is_root_term end |
#name ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def name @name end |
#namespace_prefix ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def namespace_prefix @namespace_prefix end |
#path ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def path @path end |
#required ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def required @required end |
#terminology ⇒ Object
Returns the value of attribute terminology.
128 129 130 |
# File 'lib/om/xml/term.rb', line 128 def terminology @terminology end |
#variant_of ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def variant_of @variant_of end |
#xpath ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def xpath @xpath end |
#xpath_constrained ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def xpath_constrained @xpath_constrained end |
#xpath_relative ⇒ Object
Term Class Definition
127 128 129 |
# File 'lib/om/xml/term.rb', line 127 def xpath_relative @xpath_relative end |
Class Method Details
.from_node(mapper_xml) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/om/xml/term.rb', line 146 def self.from_node(mapper_xml) name = mapper_xml.attribute("name").text.to_sym attributes = {} mapper_xml.xpath("./attribute").each do |a| attributes[a.attribute("name").text.to_sym] = a.attribute("value").text end new_mapper = self.new(name, :attributes=>attributes) [:index_as, :required, :type, :variant_of, :path, :default_content_path, :namespace_prefix].each do |accessor_name| attribute = mapper_xml.attribute(accessor_name.to_s) unless attribute.nil? new_mapper.instance_variable_set("@#{accessor_name}", attribute.text ) end end new_mapper.internal_xml = mapper_xml mapper_xml.xpath("./mapper").each do |child_node| child = self.from_node(child_node) new_mapper.add_child(child) end return new_mapper end |
Instance Method Details
#generate_xpath_queries! ⇒ Object
Generates absolute, relative, and constrained xpaths for the term, setting xpath, xpath_relative, and xpath_constrained accordingly. Also triggers update_xpath_values! on all child nodes, as their absolute paths rely on those of their parent nodes.
220 221 222 223 224 225 226 |
# File 'lib/om/xml/term.rb', line 220 def generate_xpath_queries! self.xpath = OM::XML::TermXpathGenerator.generate_absolute_xpath(self) self.xpath_constrained = OM::XML::TermXpathGenerator.generate_constrained_xpath(self) self.xpath_relative = OM::XML::TermXpathGenerator.generate_relative_xpath(self) self.children.each_value {|child| child.generate_xpath_queries! } return self end |
#is_root_term? ⇒ Boolean
188 189 190 |
# File 'lib/om/xml/term.rb', line 188 def is_root_term? @is_root_term == true end |
#retrieve_term(*pointers) ⇒ Object
crawl down into mapper’s children hash to find the desired mapper ie. @test_mapper.retrieve_mapper(:conference, :role, :text)
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/om/xml/term.rb', line 171 def retrieve_term(*pointers) children_hash = self.children pointers.each do |p| if children_hash.has_key?(p) target = children_hash[p] if pointers.index(p) == pointers.length-1 return target else children_hash = target.children end else return nil end end return target end |
#xml_builder_template(extra_opts = {}) ⇒ Object
term_pointers
reference to the property you want to generate a builder template for
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/om/xml/term.rb', line 198 def xml_builder_template(extra_opts = {}) extra_attributes = extra_opts.fetch(:attributes, {}) = [] node_child_template = "" if !self.default_content_path.nil? = ["\':::builder_new_value:::\'"] node_child_template = " { xml.#{self.default_content_path}( #{OM::XML.delimited_list()} ) }" else = ["\':::builder_new_value:::\'"] end if !self.attributes.nil? self.attributes.merge(extra_attributes).each_pair do |k,v| << ":#{k}=>\'#{v}\'" end end template = "xml.#{self.path}( #{OM::XML.delimited_list()} )" + node_child_template return template.gsub( /:::(.*?):::/ ) { '#{'+$1+'}' } end |
#xpath_absolute ⇒ Object
192 193 194 |
# File 'lib/om/xml/term.rb', line 192 def xpath_absolute @xpath end |