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, #pop_column
Methods included from TableChild
#__group_cls__, #__static_view_cls__, #__table_cls__, #__view_cls__
#==, #_get_sort_index, #apply, #colnames, #group_by, #method_missing, #ncols, #nrows, #pop_column, #respond_to?, #set_column, #sort_by, #where
Methods included from Printable
get_printable_column, get_printable_line_numbers
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
55
56
57
58
59
60
|
# File 'lib/object_table/view.rb', line 55
def cache_columns(&block)
@columns = columns
value = block.call()
@columns = nil
value
end
|
#cache_indices(&block) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/object_table/view.rb', line 44
def cache_indices(&block)
@indices = indices
value = block.call()
@indices = nil
value
end
|
#clone ⇒ Object
29
30
31
32
|
# File 'lib/object_table/view.rb', line 29
def clone
cols = ObjectTable::BasicGrid[@parent.columns.map{|k, v| [k, v[indices]]}]
__table_cls__.new(cols)
end
|
#columns ⇒ Object
51
52
53
|
# File 'lib/object_table/view.rb', line 51
def columns
@columns or super
end
|
#get_column(name) ⇒ Object
Also known as:
[]
19
20
21
22
|
# File 'lib/object_table/view.rb', line 19
def get_column(name)
col = @parent.get_column(name)
ObjectTable::MaskedColumn.mask(col, indices) if col
end
|
#indices ⇒ Object
40
41
42
|
# File 'lib/object_table/view.rb', line 40
def indices
@indices or NArray.int(@parent.nrows).indgen![@parent.apply &@filter]
end
|
#inspect(*args) ⇒ Object
34
35
36
37
38
|
# File 'lib/object_table/view.rb', line 34
def inspect(*args)
cache_columns{ super }
rescue NoMethodError => e
raise Exception.new(e)
end
|
#make_view ⇒ Object
25
26
27
|
# File 'lib/object_table/view.rb', line 25
def make_view
__static_view_cls__.new @parent, indices
end
|