Class: TJSON::DataType::Object
Overview
Constant Summary
TAGS
Instance Attribute Summary
Attributes inherited from NonScalar
#inner_type
Instance Method Summary
collapse
Methods inherited from NonScalar
#==, #initialize, #scalar?
[], generate, identify_type, parse
Instance Method Details
#convert(obj) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/tjson/datatype/object.rb', line 11
def convert(obj)
raise TJSON::TypeError, "expected TJSON::Object, got #{obj.class}" unless obj.is_a?(TJSON::Object)
obj
end
|
#generate(obj) ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/tjson/datatype/object.rb', line 18
def generate(obj)
members = obj.map do |k, v|
raise TypeError, "expected String for key, got #{k.class}" unless k.is_a?(::String)
type = TJSON::DataType.identify_type(v)
["#{k}:#{type.tag}", TJSON::DataType.generate(v)]
end
Hash[members]
end
|
28
29
30
|
# File 'lib/tjson/datatype/object.rb', line 28
def inspect
"#<#{self.class}>"
end
|
7
8
9
|
# File 'lib/tjson/datatype/object.rb', line 7
def tag
"O"
end
|