Class: Prune::PObjects::PDictionary
- Inherits:
-
Base
- Object
- Base
- Prune::PObjects::PDictionary
show all
- Defined in:
- lib/prune/p_objects/p_dictionary.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#indent!, #outdent!, #space, #value_to_s
Constructor Details
#initialize(pd = {}) ⇒ PDictionary
Returns a new instance of PDictionary.
8
9
10
11
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 8
def initialize(pd = {})
@dict = {}
@dict.update(pd)
end
|
Instance Attribute Details
#dict ⇒ Object
Returns the value of attribute dict.
6
7
8
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 6
def dict
@dict
end
|
Instance Method Details
#[](key) ⇒ Object
17
18
19
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 17
def [](key)
@dict[key]
end
|
#[]=(key, value) ⇒ Object
21
22
23
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 21
def []=(key, value)
self.update(key => value)
end
|
#empty? ⇒ Boolean
13
14
15
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 13
def empty?
return @dict.empty?
end
|
#has_key?(key) ⇒ Boolean
42
43
44
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 42
def has_key?(key)
@dict.has_key?(key)
end
|
#keys ⇒ Object
46
47
48
49
50
51
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 46
def keys
keys = @dict.keys.sort_by{|key| key.to_s}
type_key = PName.new(:Type)
keys.unshift(type_key) if keys.delete(type_key)
keys
end
|
#size ⇒ Object
53
54
55
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 53
def size
@dict.size
end
|
#to_s ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/prune/p_objects/p_dictionary.rb', line 57
def to_s
case self.size
when 0
"<< >>"
when 1
"<< %s >>" % pair_to_s(self.keys.first)
else
out = []
out << "<<"
indent!
self.keys.each{|key|
out << space + pair_to_s(key)
}
outdent!
out << space + ">>"
out.join(LF)
end
end
|