@@ -53,42 +53,53 @@ def fix_space s
53
53
54
54
# if class_name is set, mark non-matches as invisible
55
55
visible = ( type . downcase . include? ( class_name ) ) . to_s if class_name
56
+ if visible && visible == 'true'
57
+ if name == label && name == value
58
+ puts "#{ type } " if name || label || value || hint
59
+ puts " name, label, value: #{ name } " if name
60
+ puts " hint: #{ hint } " if hint
61
+ elsif name == label
62
+ puts "#{ type } " if name || label || value || hint
63
+ puts " name, label: #{ name } " if name
64
+ puts " value: #{ value } " if value
65
+ puts " hint: #{ hint } " if hint
66
+ elsif name == value
67
+ puts "#{ type } " if name || label || value || hint
68
+ puts " name, value: #{ name } " if name
69
+ puts " label: #{ label } " if label
70
+ puts " hint: #{ hint } " if hint
71
+ else
72
+ puts "#{ type } " if name || label || value || hint
73
+ puts " name: #{ name } " if name
74
+ puts " label: #{ label } " if label
75
+ puts " value: #{ value } " if value
76
+ puts " hint: #{ hint } " if hint
77
+ end
56
78
57
- if name == label && name == value
58
- puts "#{ type } " if name || label || value || hint
59
- puts " name, label, value: #{ name } " if name
60
- puts " hint: #{ hint } " if hint
61
- elsif name == label
62
- puts "#{ type } " if name || label || value || hint
63
- puts " name, label: #{ name } " if name
64
- puts " value: #{ value } " if value
65
- puts " hint: #{ hint } " if hint
66
- elsif name == value
67
- puts "#{ type } " if name || label || value || hint
68
- puts " name, value: #{ name } " if name
69
- puts " label: #{ label } " if label
70
- puts " hint: #{ hint } " if hint
71
- else
72
- puts "#{ type } " if name || label || value || hint
73
- puts " name: #{ name } " if name
74
- puts " label: #{ label } " if label
75
- puts " value: #{ value } " if value
76
- puts " hint: #{ hint } " if hint
77
- end if visible && visible == 'true'
78
-
79
- # there may be many ids with the same value.
80
- # output all exact matches.
81
- id_matches = @strings_xml . select do |key , val |
82
- val == name || val == label || val == value
83
- end
79
+ # there may be many ids with the same value.
80
+ # output all exact matches.
81
+ attributes = [ name , label , value , hint ] . select { |attr | !attr . nil? }
82
+ partial = { }
83
+ id_matches = @strings_xml . select do |key , val |
84
+ next if val . nil? || val . empty?
85
+ partial [ key ] = val if attributes . detect { |attr | attr . include? ( val ) }
86
+ attributes . detect { |attr | val == attr }
87
+ end
88
+
89
+ # If there are no exact matches, display partial matches.
90
+ id_matches = partial if id_matches . empty?
91
+
92
+ unless id_matches . empty?
93
+ match_str = ''
94
+ max_len = id_matches . keys . max_by ( &:length ) . length
84
95
85
- if id_matches && id_matches . length > 0
86
- match_str = ''
87
- # [0] = key, [1] = value
88
- id_matches . each do |match |
89
- match_str += ' ' * 7 + "#{ match [ 0 ] } \n "
96
+ # [0] = key, [1] = value
97
+ id_matches . each do |key , value |
98
+ arrow_space = ' ' * ( max_len - key . length ) . to_i
99
+ match_str += ' ' * 7 + "#{ key } #{ arrow_space } => #{ value } \n "
100
+ end
101
+ puts " id: #{ match_str . strip } \n "
90
102
end
91
- puts " id: #{ match_str . strip } \n "
92
103
end
93
104
end
94
105
0 commit comments