Class: Gloo::Objs::Table
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::Table
- Defined in:
- lib/gloo/objs/data/table.rb
Constant Summary collapse
- KEYWORD =
'table'.freeze
- KEYWORD_SHORT =
'tbl'.freeze
- HEADERS =
'headers'.freeze
- DATA =
'data'.freeze
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.
-
.show(headers, data, title = nil) ⇒ Object
Show the given table data.
-
.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.
-
#columns ⇒ Object
Get the list of column names.
-
#data ⇒ Object
Get the list of data elements.
-
#headers ⇒ Object
Get the list of headers.
-
#msg_show ⇒ Object
Show the table in the CLI.
Methods inherited from Core::Obj
#add_child, can_create?, #can_receive_message?, #child_count, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #msg_unload, #multiline_value?, #pn, #remove_child, #root?, #send_message, #set_parent, #set_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.
100 101 102 |
# File 'lib/gloo/objs/data/table.rb', line 100 def self. return super + %w[show] end |
.short_typename ⇒ Object
The short name of the object type.
29 30 31 |
# File 'lib/gloo/objs/data/table.rb', line 29 def self.short_typename return KEYWORD_SHORT end |
.show(headers, data, title = nil) ⇒ Object
Show the given table data.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/gloo/objs/data/table.rb', line 119 def self.show( headers, data, title = nil ) pastel = ::Pastel.new table = TTY::Table.new headers, data pad = [ 0, 1, 0, 1 ] rendered = table.render( :ascii, indent: 2, padding: pad ) do |r| r.border.style = :blue r.filter = proc do |val, row_index, _col_index| # col_index % 2 == 1 ? pastel.red.on_green(val) : val if row_index.zero? pastel.blue( val ) else row_index.odd? ? pastel.white( val ) : pastel.yellow( val ) end end end puts "\n#{title.white}" puts "#{rendered}\n\n" end |
.typename ⇒ Object
The name of the object type.
22 23 24 |
# File 'lib/gloo/objs/data/table.rb', line 22 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.
78 79 80 |
# File 'lib/gloo/objs/data/table.rb', line 78 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.
87 88 89 90 91 |
# File 'lib/gloo/objs/data/table.rb', line 87 def add_default_children fac = $engine.factory fac.create_can HEADERS, self fac.create_can DATA, self end |
#columns ⇒ Object
Get the list of column names. Returns nil if there is none.
48 49 50 51 52 53 |
# File 'lib/gloo/objs/data/table.rb', line 48 def columns o = find_child HEADERS return [] unless o return o.children.map( &:name ) end |
#data ⇒ Object
Get the list of data elements.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gloo/objs/data/table.rb', line 58 def data o = find_child DATA return [] unless o o = Gloo::Objs::Alias.resolve_alias( o ) cols = self.columns return o.children.map do |e| cols.map { |h| e.find_child( h ).value } end end |
#headers ⇒ Object
Get the list of headers. Returns nil if there is none.
37 38 39 40 41 42 |
# File 'lib/gloo/objs/data/table.rb', line 37 def headers o = find_child HEADERS return [] unless o return o.children.map( &:value ) end |