Class: Envo::PathListVal
Instance Attribute Summary
Attributes inherited from ListVal
#ar
Instance Method Summary
collapse
Methods inherited from ListVal
#delete, #delete_at, #insert, #invalid_description, #list?, #shift, #shift_at, #to_list, #to_s, #uniq!
Constructor Details
#initialize(host, ar) ⇒ PathListVal
Returns a new instance of PathListVal.
3
4
5
6
|
# File 'lib/envo/val/path_list_val.rb', line 3
def initialize(host, ar)
super(ar)
@host = host
end
|
Instance Method Details
#accept_assign?(other) ⇒ Boolean
10
11
12
|
# File 'lib/envo/val/path_list_val.rb', line 10
def accept_assign?(other)
other.type == type
end
|
#accept_item?(item) ⇒ Boolean
13
14
15
|
# File 'lib/envo/val/path_list_val.rb', line 13
def accept_item?(item)
item.type == :path
end
|
#clean! ⇒ Object
45
46
47
48
49
50
|
# File 'lib/envo/val/path_list_val.rb', line 45
def clean!
helper = make_helper_map
helper.select! { |e| e[:id] != -1 }
helper.uniq! { |e| e[:id] }
@ar = helper.map { |e| e[:str] }
end
|
#make_helper_map ⇒ Object
17
18
19
20
21
22
|
# File 'lib/envo/val/path_list_val.rb', line 17
def make_helper_map
@ar.map { |p|
id = @host.path_id(p)
{ str: p, id: id }
}
end
|
#pretty_print(ctx) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/envo/val/path_list_val.rb', line 24
def pretty_print(ctx)
helper = make_helper_map
ctx.puts "["
helper.each_with_index do |v, i|
dupes = helper.count { |e|
if e[:str] == v[:str] then true
elsif e[:id] == -1 then false
else e[:id] == v[:id]
end
}
str = dupes > 1 ? 'D' : ' '
str += v[:id] != -1 ? ' ' : 'N'
str += ' '
str += "#{i}:".ljust(4)
str += v[:str]
ctx.puts str
end
ctx.puts ']'
end
|
#type ⇒ Object
7
8
9
|
# File 'lib/envo/val/path_list_val.rb', line 7
def type
:"path list"
end
|