class Krikri::Parser::Value

A generic parser value.

Interface to a single value node which can access typed data values (e.g. String, DateTime, etc…) parsed from a string, and provides access to child nodes and attributes.

Public Instance Methods

[](name_exp) click to toggle source

Property accessor interface. Passes a name expression (`name_exp`) to the local implementation of get_child_nodes.

The given name expression must follow the pattern:

name [| name ...]

The optional “|” is a short-circuit operator that will return the property or element in the document for the first matching part of the phrase.

@example

va = value['title']
va = value['this|that']  # gives value for "this" if both defined

@param name [String] An expression of named properties to access @return [Krikri::Parser::ValueArray]

# File lib/krikri/parser.rb, line 62
def [](name_exp)
  name_exp.strip.split(/\s*\|\s*/).each do |n|
    result = get_child_nodes(n)
    return result unless result.empty?
  end
  Krikri::Parser::ValueArray.new([])
end
attribute?(name) click to toggle source

Queries whether `name` is an attribute of this node @param name [#to_sym] an attribute name to query @return [Boolean] true if `name` is an attribute of the current node

# File lib/krikri/parser.rb, line 112
def attribute?(name)
  begin
    attributes.include?(name)
  rescue NotImplementedError
    false
  end
end
attributes() click to toggle source

@abstract @return [Array<Symbol>] a list of attributes accessible on the node

# File lib/krikri/parser.rb, line 104
def attributes
  raise NotImplementedError
end
child?(name) click to toggle source

Queries whether `name` is a subproperty of this node @param name [#to_sym] a named property to query @return [Boolean] true if `name` is a subproperty of the current node

# File lib/krikri/parser.rb, line 74
def child?(name)
  children.include?(name)
end
children() click to toggle source

@abstract @return [Array<Symbol>] a list of subproperties that can be passed back

to #[] to access child nodes
# File lib/krikri/parser.rb, line 82
def children
  raise NotImplementedError
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/krikri/parser.rb, line 120
def method_missing(name, *args, &block)
  return attribute(name) if attribute?(name)
  super
end
respond_to_missing(method, *) click to toggle source
Calls superclass method
# File lib/krikri/parser.rb, line 125
def respond_to_missing(method, *)
  attribute?(method) || super
end
value() click to toggle source

@abstract @return [<#to_s>] typed value for the property

# File lib/krikri/parser.rb, line 89
def value
  raise NotImplementedError
end
values?() click to toggle source

@abstract @return [Boolean] true if this node has typed values accessible with

#values
# File lib/krikri/parser.rb, line 97
def values?
  raise NotImplementedError
end

Private Instance Methods

attribute(name) click to toggle source

@abstract

# File lib/krikri/parser.rb, line 133
def attribute(name)
  raise NotImplementedError, "Can't access attribute #{name}"
end
get_child_nodes(name) click to toggle source

@abstract Return a Krikri::Parser::ValueArray of child nodes

@param name [String] Element or property name @return [Krikri::Parser::ValueArray] The child nodes

# File lib/krikri/parser.rb, line 142
def get_child_nodes(name)
  raise NotImplementedError, "Can't access property #{name}"
end