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
|
# File 'lib/tb/func.rb', line 30
def self.smart_cmp_value(v)
case v
when nil
[]
when Numeric
[0, v]
when String
if v.respond_to? :force_encoding
v = v.dup.force_encoding("ASCII-8BIT")
end
case v
when /\A\s*-?\d+\s*\z/
[0, v.to_i(10)]
when /\A\s*-?(\d+(\.\d+)?)([eE][-+]?\d+)?\s*\z/
[0, Float(v)]
else
a = []
v.scan(/(\d+)|\D+/) {
if $1
a << 0 << $1.to_i
else
a << 1 << $&
end
}
a
end
else
raise ArgumentError, "unexpected: #{v.inspect}"
end
end
|