Class: Udat::Scalar

Inherits:
Node show all
Defined in:
lib/udat.rb

Overview

Class of Udat::Node’s holding scalar values (stored as a String).

Instance Attribute Summary collapse

Attributes inherited from Node

#tag

Instance Method Summary collapse

Methods inherited from Node

#==, #collection?, #encode, #encode_document, #eql?, #hash, #inspect, parse, parse_document, read_from_stream, #require_collection, #require_scalar, #require_tag, #rpc, #to_udat, #write_to_stream

Constructor Details

#initialize(tag, content) ⇒ Scalar

Creates a new Udat::Scalar with a given tag (which may be nil) and a given content, which is transformed to a string (via Object#to_s). It is not recommended to use this method. Use Object#to_udat instead.



1049
1050
1051
1052
# File 'lib/udat.rb', line 1049

def initialize(tag, content)
  super tag
  self.content = content
end

Instance Attribute Details

#contentObject

Content of the scalar (a String).



1060
1061
1062
# File 'lib/udat.rb', line 1060

def content
  @content
end

Instance Method Details

#empty?Boolean

Returns true, if the (String representation of the) content is empty.

Returns:

  • (Boolean)


1080
1081
1082
# File 'lib/udat.rb', line 1080

def empty?
  self.to_s.empty?
end

#encode_contentObject

Returns the encoded form of the content as a string. In this case this is simply an escaped version of the String.



1086
1087
1088
# File 'lib/udat.rb', line 1086

def encode_content
  Udat::escape_string(self.to_s)
end

#scalar?Boolean

Returns true.

Returns:

  • (Boolean)


1055
1056
1057
# File 'lib/udat.rb', line 1055

def scalar?
  true
end

#to_fObject

Returns the content casted to a Float.



1075
1076
1077
# File 'lib/udat.rb', line 1075

def to_f
  content.to_f
end

#to_iObject

Returns the content casted to an Integer.



1071
1072
1073
# File 'lib/udat.rb', line 1071

def to_i
  content.to_i
end

#to_sObject

Same as Udat::Scalar#content.



1067
1068
1069
# File 'lib/udat.rb', line 1067

def to_s
  content
end