module AwesomeXML::NativeType

Attributes

options[R]
string[R]

Public Class Methods

included(base) click to toggle source
# File lib/awesome_xml/native_type.rb, line 7
def self.included(base)
  base.class_eval do
    base.extend(AwesomeXML::NativeType::ClassMethods)
  end
end
new(string, options) click to toggle source

Native type instances are initialized with a ‘Nokogiri::XML` object and an options hash.

# File lib/awesome_xml/native_type.rb, line 17
def initialize(string, options)
  @string = string
  @options = options
end

Public Instance Methods

evaluate() click to toggle source

This method returns the parsed value of the given node (obtained by calling ‘#text` on it) according to the implementation of the private method `#parse_value` defined in every native type class.

# File lib/awesome_xml/native_type.rb, line 24
def evaluate
  @value ||= with_defaults { parse_value }
end

Private Instance Methods

default_empty() click to toggle source
# File lib/awesome_xml/native_type.rb, line 43
def default_empty
  nil
end
with_defaults() { || ... } click to toggle source
# File lib/awesome_xml/native_type.rb, line 36
def with_defaults(&block)
  return options[:default] if string.nil?
  return options[:default_empty] if options.has_key?(:default_empty) && string.empty?
  return default_empty if string.empty?
  yield
end