Class: Gloo::Objs::Outline
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::Outline
- Defined in:
- lib/gloo/objs/str_utils/outline.rb
Constant Summary collapse
- KEYWORD =
'outline'.freeze
- KEYWORD_SHORT =
'outline'.freeze
- OBJ_SOURCE =
'object_source'.freeze
- DATA =
'data'.freeze
- SEPARATOR =
'separator_char'.freeze
- DEFAULT_SEPARATOR =
'/'.freeze
- ENTITY_PATH =
'entity_path'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#add_item(in_container, name, id) ⇒ Object
Add the item to the container.
-
#add_topic(id, name) ⇒ Object
Add the item to the topics array, but break multi-segment topics into component segments.
-
#data ⇒ Object
Get the data value of the object.
-
#entity_path ⇒ Object
Get the entity path.
-
#find_segment(in_container, name) ⇒ Object
Find the segment.
-
#msg_generate ⇒ Object
Generate an outline from the source objects.
-
#obj_source ⇒ Object
Get the source value of the object.
-
#render_outline ⇒ Object
Render Outline.
-
#render_outline_r(in_container) ⇒ Object
Render the outline recursively.
-
#separator_char ⇒ Object
Get the separator character.
-
#show_items_r(in_container, indent) ⇒ Object
Debugging Tool shows topic hierarchy in console.
-
#update_data(new_val) ⇒ Object
Update the data value of the object.
Methods inherited from Core::Obj
#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #set_value, #sql_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
121 122 123 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 121 def self. return super + %w[generate] end |
.short_typename ⇒ Object
The short name of the object type.
30 31 32 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 30 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
23 24 25 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 23 def self.typename return KEYWORD end |
Instance Method Details
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
96 97 98 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 96 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
105 106 107 108 109 110 111 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 105 def add_default_children fac = @engine.factory fac.create_alias OBJ_SOURCE, nil, self fac.create_string ENTITY_PATH, nil, self fac.create_string SEPARATOR, '/', self fac.create_string DATA, nil, self end |
#add_item(in_container, name, id) ⇒ Object
Add the item to the container. Used to create the leaf of the tree. It might be a branch later on.
180 181 182 183 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 180 def add_item( in_container, name, id ) item = { name: name, children: [], id: id } in_container[ :children ] << item end |
#add_topic(id, name) ⇒ Object
Add the item to the topics array, but break multi-segment topics into component segments.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 160 def add_topic id, name segments = name.split( separator_char ) path_segments = segments[0..-2] last_segment = segments.last parent = @root if segments.count > 1 path_segments.each do |segment| parent = find_segment( parent, segment ) end end add_item( parent, last_segment, id ) end |
#data ⇒ Object
Get the data value of the object. This might be encrypted or decrypted based on what action was last taken.
58 59 60 61 62 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 58 def data o = find_child DATA o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o&.value end |
#entity_path ⇒ Object
Get the entity path.
67 68 69 70 71 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 67 def entity_path o = find_child ENTITY_PATH o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o&.value end |
#find_segment(in_container, name) ⇒ Object
Find the segment. If not found, create it.
189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 189 def find_segment( in_container, name ) in_container[ :children ].each do |item| if item[ :name ] == name return item end end # Container not found, create it. item = { name: name, id: nil, children: [] } in_container[ :children ] << item return item end |
#msg_generate ⇒ Object
Generate an outline from the source objects.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 128 def msg_generate @root = { name: 'root', id: nil, children: [] } # Get Topics from the source container src = obj_source return unless src # Build the outline structure src.children.each do |o| id = o.children[0].value name = o.children[1].value add_topic id, name end # show_items_r( @root[ :children ], 0 ) # Generate the HTML from the outline structure html = render_outline # Update the data value update_data( html ) end |
#obj_source ⇒ Object
Get the source value of the object. Returns nil if there is none.
38 39 40 41 42 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 38 def obj_source o = find_child OBJ_SOURCE o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o end |
#render_outline ⇒ Object
Render Outline
210 211 212 213 214 215 216 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 210 def render_outline @html = "" @path = entity_path render_outline_r( @root[ :children ] ) return @html end |
#render_outline_r(in_container) ⇒ Object
Render the outline recursively.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 221 def render_outline_r( in_container ) @html << "<ul>\n" in_container.each do |item| if item[ :id ] && @path url = "#{@path}#{item[ :id ]}" @html << "<li><a href='#{url}'>#{item[ :name ]}</a></li>\n" else @html << "<li>#{item[ :name ]}</li>\n" end if item[ :children ] && ( item[ :children ].count > 0 ) render_outline_r( item[ :children ] ) end end @html << "</ul>\n" end |
#separator_char ⇒ Object
Get the separator character.
47 48 49 50 51 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 47 def separator_char o = find_child SEPARATOR o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o&.value || DEFAULT_SEPARATOR end |
#show_items_r(in_container, indent) ⇒ Object
Debugging Tool shows topic hierarchy in console. This is a recursive function.
246 247 248 249 250 251 252 253 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 246 def show_items_r( in_container, indent ) in_container.each do |item| puts "#{' ' * indent}#{item[ :name ]} (#{item[ :id ]})" if item[ :children ] && ( item[ :children ].count > 0 ) show_items_r( item[ :children ], indent + 3 ) end end end |
#update_data(new_val) ⇒ Object
Update the data value of the object.
76 77 78 79 80 81 82 83 84 |
# File 'lib/gloo/objs/str_utils/outline.rb', line 76 def update_data( new_val ) o = find_child DATA return unless o o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return unless o o.set_value new_val end |