lib/jini.rb in jini-0.0.7 vs lib/jini.rb in jini-0.0.8
- old
+ new
@@ -40,57 +40,75 @@
@head = head
end
# Convert it to a string.
# @return [String] xpath as string
+ # @raise [InvalidPath] if contain spaces in simple nodes
def to_s
+ copy = @head.split(%r{//|/})
+ copy.each do |node|
+ if !node.match(/[|]|@|=|>|</) && node.include?(' ')
+ raise InvalidPath, "Nodes can't contain spaces: #{node} – contain space."
+ end
+ end
@head.to_s
end
# Additional node for xpath.
# @param node [String] node
# @return [Jini] object
def add_node(node)
Jini.new("#{@head}/#{node}")
end
+ # Addition property in tail
+ # Before: '../child'
+ # After: '../child/property()'
+ # @param property [String]
+ # @return [Jini] object
+ def add_property(property)
+ Jini.new(add_node("#{property}()").to_s)
+ end
+
# Additional attribute for xpath.
# '[@key="value"]'
# @param key [String] name of attr
# @param value [String] value of attr
# @return [Jini] object
def add_attr(key, value)
Jini.new("#{@head}[@#{key}=\"#{value}\"]")
end
- # Adds an @value to xpath
+ # Adds '@value' to tail
# @param value [String] with value attr
# @return [Jini] object
- def all_attr(value)
+ def add_attrs(value)
Jini.new("#{@head}@#{value}")
end
# Xpath with all elements.
# Addition an '*' to tail of xpath
# @return [Jini] object
+ # @raise [InvalidPath] when method called after attr
def all
raise InvalidPath, 'You cannot add all tag after attr!' if @head[-1].eql?(']')
Jini.new(add_node('*').to_s)
end
# Xpath with all named elements.
# Addition '//node' to xpath
# @param node [String] name of node
# @return [Jini] object
- def add_all(node)
+ def add_nodes(node)
Jini.new("#{@head}//#{node}")
end
# Access by index.
# Addition '[index]' to xpath
# @param position [Integer] number
# @return [Jini] object
+ # @raise [InvalidPath] when method used after selection
def at(position)
raise InvalidPath, 'Cant use at after selection' if @head.include? '::'
Jini.new("#{@head}[#{position}]")
end
@@ -125,13 +143,13 @@
Jini.new(
purge(/(\[@?#{name}="[^"]+"(\[\]+|\]))/)
)
end
- # Adds '|' to head
+ # Adds '[alpha | beta]' in tail.
# @param [String] alpha statement
# @param [String] beta statement
- # @return [Jini] with Jini '[first|second]' on tail
+ # @return [Jini] with '[first|second]' on tail
def or(alpha, beta)
action_between('|', alpha, beta)
end
# Less than.