class PIM::XmlItem

Attributes

category[R]
primary_key[R]
values[R]
xml[R]

Public Class Methods

new(xml, args = {}) click to toggle source
# File pim.rb, line 2296
def initialize xml, args = {}
  @xml = xml
  @category = PIM.get_value(args, :category)
  @primary_key = PIM.get_value(args, :primary_key)
  @values = PIM.get_value(args, :values)
  @cache = {}
end

Public Instance Methods

execute_xml_rule(failure_message, opts = {}) click to toggle source
# File pim.rb, line 2304
def execute_xml_rule failure_message, opts = {}, &xml_rule_block
  begin
    @failure_level = opts[:failure_level]
    @failure_message = failure_message
    @failure_params = opts[:failure_params]
    self.instance_eval &xml_rule_block
  ensure
    @failure_level = nil
    @failure_message = nil
    @failure_params = nil
  end
end
fail(*args) click to toggle source
# File pim.rb, line 2317
def fail *args
  if args.length == 0
    Kernel.fail ValidationFailure.new(failure_level: @failure_level,
                                      failure_message: @failure_message,
                                      failure_params: @failure_params)
  elsif args.length == 1 and PIM.is_hash?(args[0])
    failure_params = {}
    failure_params.merge!(@failure_params) unless @failure_params.nil?
    failure_params.merge!(args[0])
    Kernel.fail ValidationFailure.new(failure_level: @failure_level,
                                      failure_message: @failure_message,
                                      failure_params: failure_params)
  else
    Kernel.fail *args
  end
end
method_missing(name, *args, &block) click to toggle source
# File pim.rb, line 2334
def method_missing name, *args, &block
  name = name.to_s.split(":", 2).last.to_sym
  if @cache.has_key?(name)
    return @cache[name]
  end
  nodes = XmlUtils.xpath(xml, "./#{name}")
  if nodes.empty?
    nodes = XmlUtils.xpath(xml, "./#{name}Code")
  end
  if nodes.empty?
    nodes = XmlUtils.xpath(xml, ".//#{name}")
  end
  if nodes.empty?
    nodes = XmlUtils.xpath(xml, ".//#{name}Code")
  end
  if nodes.size > 1
    return parse_array_for_xpath(name)
  end
  if nodes.empty? or nodes[0].nil?
    cache(name, NodeValue.new(nil))
  elsif nodes[0].text.to_s.downcase == 'false'
    cache(name, NodeValue.new(false))
  else
    node = create_node_value_with_attributes(nodes[0])
    cache(name, node)
  end
end