Class: StatusManager::StatusStore
- Inherits:
-
Object
- Object
- StatusManager::StatusStore
- Defined in:
- lib/status-manager/status_store.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
Returns the value of attribute attribute_name.
-
#group_statuses ⇒ Object
Returns the value of attribute group_statuses.
-
#status_sets ⇒ Object
Returns the value of attribute status_sets.
Instance Method Summary collapse
- #add_group_status(group_status_name, statuses) ⇒ Object
- #get_group_status(group_status_name) ⇒ Object
- #group_status?(group_status) ⇒ Boolean
-
#initialize(attribute_name, status_sets = nil) ⇒ StatusStore
constructor
A new instance of StatusStore.
- #status?(status) ⇒ Boolean
- #statuses ⇒ Object
- #value(status) ⇒ Object
- #values(statuses = []) ⇒ Object
Constructor Details
#initialize(attribute_name, status_sets = nil) ⇒ StatusStore
Returns a new instance of StatusStore.
21 22 23 24 25 |
# File 'lib/status-manager/status_store.rb', line 21 def initialize(attribute_name, status_sets = nil) @attribute_name = attribute_name @status_sets = status_sets || {} @group_statuses = {} end |
Instance Attribute Details
#attribute_name ⇒ Object
Returns the value of attribute attribute_name.
19 20 21 |
# File 'lib/status-manager/status_store.rb', line 19 def attribute_name @attribute_name end |
#group_statuses ⇒ Object
Returns the value of attribute group_statuses.
19 20 21 |
# File 'lib/status-manager/status_store.rb', line 19 def group_statuses @group_statuses end |
#status_sets ⇒ Object
Returns the value of attribute status_sets.
19 20 21 |
# File 'lib/status-manager/status_store.rb', line 19 def status_sets @status_sets end |
Instance Method Details
#add_group_status(group_status_name, statuses) ⇒ Object
43 44 45 |
# File 'lib/status-manager/status_store.rb', line 43 def add_group_status(group_status_name, statuses) @group_statuses.merge!(group_status_name => statuses) end |
#get_group_status(group_status_name) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/status-manager/status_store.rb', line 47 def get_group_status(group_status_name) statuses = {} @group_statuses[group_status_name].each do |status| statuses[status] = value(status) end statuses end |
#group_status?(group_status) ⇒ Boolean
39 40 41 |
# File 'lib/status-manager/status_store.rb', line 39 def group_status?(group_status) @group_statuses.key?(group_status) end |
#status?(status) ⇒ Boolean
31 32 33 |
# File 'lib/status-manager/status_store.rb', line 31 def status?(status) @status_sets.key?(status) end |
#statuses ⇒ Object
27 28 29 |
# File 'lib/status-manager/status_store.rb', line 27 def statuses @status_sets.keys end |
#value(status) ⇒ Object
35 36 37 |
# File 'lib/status-manager/status_store.rb', line 35 def value(status) @status_sets[status] end |
#values(statuses = []) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/status-manager/status_store.rb', line 55 def values(statuses = []) if statuses.nil? return @statuse_sets.values elsif status? statuses return [value(statuses)] elsif group_status? statuses return get_group_status(statuses).values elsif statuses.instance_of?(Array) results = [] statuses.each do |_status| if status?(_status) results << value(_status) elsif group_status?(_status) results |= get_group_status(_status).values end end return results.uniq else return [] end end |