Class: TJSON::DataType::String

Inherits:
Scalar show all
Defined in:
lib/tjson/datatype/string.rb

Overview

Unicode String type

Constant Summary

Constants inherited from TJSON::DataType

TAGS

Instance Method Summary collapse

Methods inherited from Scalar

#inspect, #scalar?

Methods inherited from TJSON::DataType

[], generate, identify_type, parse

Instance Method Details

#convert(str) ⇒ Object

Raises:



11
12
13
14
15
# File 'lib/tjson/datatype/string.rb', line 11

def convert(str)
  raise TJSON::TypeError, "expected String, got #{str.class}: #{str.inspect}" unless str.is_a?(::String)
  raise TJSON::EncodingError, "expected UTF-8, got #{str.encoding.inspect}" unless str.encoding == Encoding::UTF_8
  str
end

#generate(obj) ⇒ Object



17
18
19
# File 'lib/tjson/datatype/string.rb', line 17

def generate(obj)
  obj.to_s
end

#tagObject



7
8
9
# File 'lib/tjson/datatype/string.rb', line 7

def tag
  "s"
end