Class: ObjectTable::View
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- ViewMethods
- Defined in:
- lib/object_table/view.rb
Instance Attribute Summary
Attributes included from TableMethods
#R
Instance Method Summary
collapse
#add_column, #get_column, #nrows, #pop_column
Methods included from TableChild
#__group_cls__, #__static_view_cls__, #__table_cls__, #__view_cls__
#==, #_apply_block, #_get_sort_index, #apply, #colnames, #group_by, #method_missing, #ncols, #nrows, #pop_column, #respond_to?, #set_column, #sort_by, #where
Methods included from Printable
#_format_rows, #_format_section, calc_column_widths, get_printable_column
Constructor Details
#initialize(parent, &block) ⇒ View
Returns a new instance of View.
11
12
13
14
15
|
# File 'lib/object_table/view.rb', line 11
def initialize(parent, &block)
super()
@parent = parent
@filter = block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ObjectTable::TableMethods
Instance Method Details
#cache_columns(&block) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/object_table/view.rb', line 47
def cache_columns(&block)
@columns = columns
value = block.call()
@columns = nil
value
end
|
#cache_indices(&block) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/object_table/view.rb', line 36
def cache_indices(&block)
@indices = indices
value = block.call()
@indices = nil
value
end
|
#clone ⇒ Object
21
22
23
24
|
# File 'lib/object_table/view.rb', line 21
def clone
cols = ObjectTable::BasicGrid[@parent.columns.map{|k, v| [k, v[false, indices]]}]
__table_cls__.new(cols)
end
|
#columns ⇒ Object
43
44
45
|
# File 'lib/object_table/view.rb', line 43
def columns
@columns or super
end
|
#indices ⇒ Object
32
33
34
|
# File 'lib/object_table/view.rb', line 32
def indices
@indices or NArray.int(@parent.nrows).indgen![@parent._apply_block &@filter]
end
|
#inspect(*args) ⇒ Object
26
27
28
29
30
|
# File 'lib/object_table/view.rb', line 26
def inspect(*args)
cache_columns{ super }
rescue NoMethodError => e
raise Exception.new(e)
end
|
#make_view ⇒ Object
17
18
19
|
# File 'lib/object_table/view.rb', line 17
def make_view
__static_view_cls__.new @parent, indices
end
|