1 |
# frozen_string_literal: true
|
|
2 |
|
|
3 |
require "yaml"
|
× |
4 |
|
|
5 |
module WhatsOpt |
× |
6 |
module Utils |
× |
7 |
def shape_of(str) |
× |
8 |
if /\[(.*)\]/.match?(str) |
× |
9 |
ary = YAML.load(str)
|
× |
10 |
"(#{ary.size},#{_dim(ary.first)})"
|
× |
11 |
else
|
× |
12 |
"1"
|
× |
13 |
end
|
× |
14 |
end
|
× |
15 |
|
|
16 |
private |
× |
17 |
def _dim(ary) |
× |
18 |
if ary.is_a? Array |
× |
19 |
res = "#{ary.size}"
|
× |
20 |
sub = _dim(ary.first) |
× |
21 |
unless sub.blank?
|
× |
22 |
res += ",#{sub}"
|
× |
23 |
end
|
× |
24 |
res |
× |
25 |
else
|
× |
26 |
""
|
× |
27 |
end
|
× |
28 |
end
|
× |
29 |
end
|
× |
30 |
end
|
× |