class AwesomeXML::NodeXPath

Attributes

node_name[R]
options[R]

Public Class Methods

new(node_name, options) click to toggle source

Initialize this class by providing the name of the ‘AwesomeXML` node and an options hash. For more information on how the options work, please refer to the README.

# File lib/awesome_xml/node_xpath.rb, line 11
def initialize(node_name, options)
  @node_name = node_name
  @options = options
end

Public Instance Methods

xpath() click to toggle source

Returns a String representing an XPath built from the options passed in at initialization time.

# File lib/awesome_xml/node_xpath.rb, line 17
def xpath
  options[:xpath] || xpath_by_tag_type
end

Private Instance Methods

node_name_singular() click to toggle source
# File lib/awesome_xml/node_xpath.rb, line 37
def node_name_singular
  options[:array] ? node_name.to_s.singularize.to_sym : node_name
end
tag_name(option) click to toggle source
# File lib/awesome_xml/node_xpath.rb, line 41
def tag_name(option)
  (option if option != true) || node_name_singular
end
xpath_by_tag_type() click to toggle source
# File lib/awesome_xml/node_xpath.rb, line 23
def xpath_by_tag_type
  if options[:attribute]
    "./@#{tag_name(options[:attribute])}"
  elsif options[:attribute_name]
    "./@#{tag_name(true)}"
  elsif options[:self] || options[:self_name]
    "."
  elsif options[:element_name]
    "./#{tag_name(true)}"
  else
    "./#{tag_name(options[:element])}"
  end
end