Class: CBOR::Transform
Instance Method Summary
collapse
Instance Method Details
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/cbor-transform.rb', line 3
def transform(obj)
case obj
when NilClass
transform_nil(obj)
when FalseClass, TrueClass
transform_bool(obj)
when CBOR::Simple
transform_simple(obj)
when Float
transform_float(obj)
when Integer
transform_integer(obj)
when String
case obj.encoding
when Encoding::BINARY
transform_bytes(obj)
else
transform_text(obj)
end
when Array
transform_array(obj)
when Hash
transform_hash(obj)
when CBOR::Tagged
transform_tag(obj)
end
end
|
60
61
62
|
# File 'lib/cbor-transform.rb', line 60
def transform_array(obj)
obj.map {|x| transform(x)}
end
|
36
37
38
|
# File 'lib/cbor-transform.rb', line 36
def transform_bool(obj)
obj
end
|
52
53
54
|
# File 'lib/cbor-transform.rb', line 52
def transform_bytes(obj)
obj
end
|
44
45
46
|
# File 'lib/cbor-transform.rb', line 44
def transform_float(obj)
obj
end
|
64
65
66
|
# File 'lib/cbor-transform.rb', line 64
def transform_hash(obj)
Hash[obj.map {|k, v| [transform(k), transform(v)]}]
end
|
48
49
50
|
# File 'lib/cbor-transform.rb', line 48
def transform_integer(obj)
obj
end
|
32
33
34
|
# File 'lib/cbor-transform.rb', line 32
def transform_nil(obj)
obj
end
|
40
41
42
|
# File 'lib/cbor-transform.rb', line 40
def transform_simple(obj)
obj
end
|
68
69
70
|
# File 'lib/cbor-transform.rb', line 68
def transform_tag(obj)
CBOR::Tagged.new(transform(obj.tag), transform(obj.value))
end
|
#transform_text(obj) ⇒ Object
56
57
58
|
# File 'lib/cbor-transform.rb', line 56
def transform_text(obj)
obj
end
|