Class: Rubyang::Database::DataTree::Leaf

Inherits:
LeafNode show all
Defined in:
lib/rubyang/database/data_tree.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #parent, #schema, #schema_tree

Instance Method Summary collapse

Methods inherited from Node

#evaluate_max_elements, #evaluate_min_elements, #evaluate_musts, #evaluate_whens, #evaluate_xpath, #evaluate_xpath_axis, #evaluate_xpath_expr, #evaluate_xpath_node_test, #evaluate_xpath_path, #evaluate_xpath_predicates, #initialize, #load_merge_xml_recursive, #root, #to_json, #to_s, #to_xml, #valid?

Constructor Details

This class inherits a constructor from Rubyang::Database::DataTree::Node

Instance Attribute Details

#valueObject

Returns the value of attribute value.



960
961
962
# File 'lib/rubyang/database/data_tree.rb', line 960

def value
  @value
end

Instance Method Details

#has_value?Boolean

Returns:

  • (Boolean)


976
977
978
979
980
981
982
# File 'lib/rubyang/database/data_tree.rb', line 976

def has_value?
  if @value
    true
  else
    false
  end
end

#set(arg) ⇒ Object



961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'lib/rubyang/database/data_tree.rb', line 961

def set arg
  case @schema.type
  when SchemaTree::LeafrefType
    elements = self.evaluate_xpath( @schema.type.path )
    values = elements.inject([]){ |vs, v| vs + [v.value] }
    unless values.include? arg
      raise ArgumentError, "#{arg} is not valid for #{@schema.type.inspect}"
    end
  else
    unless @schema.type.valid? arg
      raise ArgumentError, "#{arg} is not valid for #{@schema.type.inspect}"
    end
  end
  self.value = arg
end

#to_json_recursive(_hash) ⇒ Object



991
992
993
994
# File 'lib/rubyang/database/data_tree.rb', line 991

def to_json_recursive _hash
  hash = _hash
  hash[@schema.model.arg] = @value
end

#to_xml_recursive(_doc, current_namespace) ⇒ Object



983
984
985
986
987
988
989
990
# File 'lib/rubyang/database/data_tree.rb', line 983

def to_xml_recursive _doc, current_namespace
  doc = _doc.add_element( @schema.model.arg )
  unless @schema.namespace == current_namespace
    current_namespace = @schema.namespace
    doc.add_namespace current_namespace
  end
  doc.add_text( @value )
end