Class: Udat::Scalar
Overview
Class of Udat::Node’s holding scalar values (stored as a String).
Instance Attribute Summary collapse
-
#content ⇒ Object
Content of the scalar (a String).
Attributes inherited from Node
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Returns true, if the (String representation of the) content is empty.
-
#encode_content ⇒ Object
Returns the encoded form of the content as a string.
-
#initialize(tag, content) ⇒ Scalar
constructor
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).
-
#scalar? ⇒ Boolean
Returns true.
-
#to_f ⇒ Object
Returns the content casted to a Float.
-
#to_i ⇒ Object
Returns the content casted to an Integer.
-
#to_s ⇒ Object
Same as Udat::Scalar#content.
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
#content ⇒ Object
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.
1080 1081 1082 |
# File 'lib/udat.rb', line 1080 def empty? self.to_s.empty? end |
#encode_content ⇒ Object
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.
1055 1056 1057 |
# File 'lib/udat.rb', line 1055 def scalar? true end |
#to_f ⇒ Object
Returns the content casted to a Float.
1075 1076 1077 |
# File 'lib/udat.rb', line 1075 def to_f content.to_f end |
#to_i ⇒ Object
Returns the content casted to an Integer.
1071 1072 1073 |
# File 'lib/udat.rb', line 1071 def to_i content.to_i end |
#to_s ⇒ Object
Same as Udat::Scalar#content.
1067 1068 1069 |
# File 'lib/udat.rb', line 1067 def to_s content end |