Class: UdatScalar

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

Overview

Class of UDAT objects holding scalar values (stored as a String).

Constant Summary

Constants inherited from Udat

Udat::ExampleDocument, Udat::KeepTag

Instance Attribute Summary collapse

Attributes inherited from Udat

#tag

Instance Method Summary collapse

Methods inherited from Udat

#==, #collection?, #encode, #eql?, escape_string, #hash, #inspect, parse, read_from_stream, #scalar?, #to_udat, #write_to_stream

Constructor Details

#initialize(tag, content) ⇒ UdatScalar

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



920
921
922
923
# File 'lib/udat.rb', line 920

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

Instance Attribute Details

#contentObject

Content of the scalar (a String).



926
927
928
# File 'lib/udat.rb', line 926

def content
  @content
end

Instance Method Details

#empty?Boolean

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

Returns:

  • (Boolean)


942
943
944
# File 'lib/udat.rb', line 942

def empty?
  self.to_s.empty?
end

#encoded_contentObject

Returns the encoded form of the content as a string. In this case this is simply an escaped version of the String. This method is used by Udat#encode, which returns the complete encoding of the data (including the tag).



950
951
952
# File 'lib/udat.rb', line 950

def encoded_content
  escape_string(self.to_s)
end

#to_iObject

Returns the content casted to an Integer.



937
938
939
# File 'lib/udat.rb', line 937

def to_i
  content.to_i
end

#to_sObject

Same as UdatScalar#content.



933
934
935
# File 'lib/udat.rb', line 933

def to_s
  content
end