Class: UU::OS::GVC::Container
- Inherits:
-
Object
- Object
- UU::OS::GVC::Container
- Defined in:
- uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb
Overview
Abstract container for managing components.
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (Object) add_message(message)
Adds global container message.
-
- (Array<UU::OS::GVC::Component>) components
Returns list of all components in container.
-
- (FalseClass, TrueClass) focus(component_id)
Sets focus to component with given ID.
-
- (Object) focused_component
Returns component marked as focused.
-
- (UU::OS::GVC::Component) get_component_by_id(id)
Finds single component matching given unique ID.
-
- (Array<UU::OS::GVC::Component>) get_components_by_code(code)
Finds all components matching given code.
-
- (Container) initialize(data = nil)
constructor
Creates new instance of container.
-
- (Array<UU::OS::GVC::Message>) messages
Returns list of all messages in container (both global and component related).
Constructor Details
- (Container) initialize(data = nil)
Creates new instance of container.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 18 def initialize(data = nil) @components = {} @messages = [] @focus_on = nil if data.nil? return end if data.kind_of?String data = JSON.parse(data, :symbolize_names => true) end if !data.kind_of?Hash raise ArgumentError.new("Container data must be JSON String or Hash, but was #{data.class}.") end if data[:components] data[:components].each do |cmp| component = create_component(cmp) if (@components[component.id]) raise ArgumentError.new('Invalid container data. Container contains multiple components with same ID.') end @components[component.id] = component end end if data[:messages] data[:messages].each do || () end end end |
Instance Method Details
- (Object) add_message(message)
Adds global container message.
80 81 82 83 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 80 def () msg = UU::OS::GVC::Message.new() @messages << msg end |
- (Array<UU::OS::GVC::Component>) components
Returns list of all components in container.
73 74 75 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 73 def components @components.values end |
- (FalseClass, TrueClass) focus(component_id)
Sets focus to component with given ID. Actual behavior of focus depends on type of focused component and also on type of container in which is component placed. Only one component can be focused, setting focus on one component disables focus of previously focused component within container.
102 103 104 105 106 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 102 def focus(component_id) return false if !get_component_by_id(component_id) @focus_on = component_id return true end |
- (Object) focused_component
Returns component marked as focused. Nil in case no focus is set to any component.
@return Focused component or nil
111 112 113 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 111 def focused_component @components[@focus_on] end |
- (UU::OS::GVC::Component) get_component_by_id(id)
Finds single component matching given unique ID.
52 53 54 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 52 def get_component_by_id(id) @components[id] end |
- (Array<UU::OS::GVC::Component>) get_components_by_code(code)
Finds all components matching given code. If nil is entered as the code, than all components without a defined code are returned.
62 63 64 65 66 67 68 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 62 def get_components_by_code(code) result = [] @components.values.each do |component| result << component if component.code == code end result end |
- (Array<UU::OS::GVC::Message>) messages
Returns list of all messages in container (both global and component related).
88 89 90 91 |
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/container.rb', line 88 def # Disallow direct manipulating with messages @messages.clone end |