14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/hocon/impl/default_transformer.rb', line 14
def self.transform(value, requested)
if value.value_type == ConfigValueType::STRING
s = value.unwrapped
case requested
when ConfigValueType::NUMBER
begin
v = Integer(s)
return ConfigInt.new(value.origin, v, s)
rescue ArgumentError
end
begin
v = Float(s)
return ConfigFloat.new(value.origin, v, s)
rescue ArgumentError
end
when ConfigValueType::NULL
if s == "null"
return ConfigNull.new(value.origin)
end
when ConfigValueType::BOOLEAN
if s == "true" || s == "yes" || s == "on"
return ConfigBoolean.new(value.origin, true)
elsif s == "false" || s == "no" || s == "off"
return ConfigBoolean.new(value.origin, false)
end
when ConfigValueType::LIST
when ConfigValueType::OBJECT
when ConfigValueType::STRING
end
elsif requested == ConfigValueType::STRING
case value.value_type
when ConfigValueType::NUMBER
return ConfigString::Quoted.new(value.origin, value.transform_to_string)
when ConfigValueType::BOOLEAN
return ConfigString::Quoted.new(value.origin, value.transform_to_string)
when ConfigValueType::NULL
when ConfigValueType::OBJECT
when ConfigValueType::LIST
when ConfigValueType::STRING
end
elsif requested == ConfigValueType::LIST && value.value_type == ConfigValueType::OBJECT
o = value
values = Hash.new
values
o.keys.each do |key|
begin
i = Integer(key, 10)
if i < 0
next
end
values[key] = i
rescue ArgumentError
next
end
end
if not values.empty?
entry_list = values.to_a
entry_list.sort! {|a,b| b[0] <=> a[0]}
list = Array.new
entry_list.each do |entry|
list.push(entry[1])
end
return SimpleConfigList.new(value.origin, list)
end
end
value
end
|