lib/jini.rb in jini-0.0.9 vs lib/jini.rb in jini-0.1.0

- old
+ new

@@ -58,13 +58,11 @@ # Removes node by name # @param node [String] name of node for removal # @return [Jini] without a node def remove_node(node) - Jini.new( - purge_head("/#{node}") - ) + Jini.new(purge_head("/#{node}")) end # This method replaces *all* origins to new # @param [String] origin node # @param [String] new node @@ -100,10 +98,38 @@ # @return [Jini] object def add_attrs(value) Jini.new("#{@head}@#{value}") end + # Removes attr by name. + # before: + # '/parent/child [@k="v"]' + # after: + # '/parent/child' + # @param [String] name of attr + # @return [Jini] without an attr + def remove_attr(name) + Jini.new( + purge_head(/(\[@?#{name}="[^"]+"(\[\]+|\]))/) + ) + end + + # Replaces *all* attr *values* by name. + # Before: + # '[@id="some value"]' + # After: + # [@id="new value"] + # @param name [String] of attr + # @param value [String] upd value + # @return [Jini] updated + def new_attr_value(name, value) + n_rex = /(\[@?#{name}="[^"]+"(\[\]+|\]))/ + attr = @head[n_rex] + attr[/"(.*?)"/] = "\"#{value}\"" + Jini.new(@head.gsub(n_rex, attr)) unless attr.nil? + end + # Xpath with all elements. # Addition an '*' to tail of xpath # @return [Jini] object # @raise [InvalidPath] when method called after attr def all @@ -134,22 +160,9 @@ # @return [Jini] selection # @raise [InvalidPath] when path can't present with select def selection raise InvalidPath, 'Cannot select, path contains bad symbols' if bad_symbols? @head Jini.new(@head.gsub('/', '::').to_s) - end - - # Removes attr by name. - # before: - # '/parent/child [@k="v"]' - # after: - # '/parent/child' - # @param [String] name of attr - # @return [Jini] without an attr - def remove_attr(name) - Jini.new( - purge_head(/(\[@?#{name}="[^"]+"(\[\]+|\]))/) - ) end # Adds '[alpha | beta]' in tail. # @param [String] alpha statement # @param [String] beta statement