Class: ActiveFacts::API::RoleValues
- Inherits:
-
Object
- Object
- ActiveFacts::API::RoleValues
- Includes:
- Enumerable
- Defined in:
- lib/activefacts/api/role_values.rb
Overview
:nodoc:
Instance Method Summary collapse
- #+(a) ⇒ Object
- #-(a) ⇒ Object
- #each(&b) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ RoleValues
constructor
begin.
- #single ⇒ Object
- #size ⇒ Object
- #update(old, value) ⇒ Object
- #verbalise ⇒ Object
Constructor Details
#initialize ⇒ RoleValues
begin
18 19 20 |
# File 'lib/activefacts/api/role_values.rb', line 18 def initialize @a = [] end |
Instance Method Details
#+(a) ⇒ Object
36 37 38 |
# File 'lib/activefacts/api/role_values.rb', line 36 def +(a) @a.+(a.is_a?(RoleValues) ? Array(a) : a) end |
#-(a) ⇒ Object
40 41 42 |
# File 'lib/activefacts/api/role_values.rb', line 40 def -(a) @a - a end |
#each(&b) ⇒ Object
22 23 24 25 26 |
# File 'lib/activefacts/api/role_values.rb', line 22 def each &b # REVISIT: Provide a configuration variable to enable this heckling during testing: #@a.sort_by{rand}.each &b @a.each &b end |
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/activefacts/api/role_values.rb', line 32 def empty? @a.size == 0 end |
#single ⇒ Object
44 45 46 |
# File 'lib/activefacts/api/role_values.rb', line 44 def single @a.size > 1 ? nil : @a[0] end |
#size ⇒ Object
28 29 30 |
# File 'lib/activefacts/api/role_values.rb', line 28 def size @a.size end |
#update(old, value) ⇒ Object
48 49 50 51 52 |
# File 'lib/activefacts/api/role_values.rb', line 48 def update(old, value) @a.delete(old) if old @a << value if value raise "Adding RoleProxy to RoleValues collection" if value && RoleProxy === value end |
#verbalise ⇒ Object
54 55 56 |
# File 'lib/activefacts/api/role_values.rb', line 54 def verbalise "["+@a.to_a.map{|e| e.verbalise}*", "+"]" end |