Class: ObjectTable::View

Inherits:
Object
  • 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

Methods included from ViewMethods

#add_column, #get_column, #nrows, #pop_column

Methods included from TableChild

#__group_cls__, #__static_view_cls__, #__table_cls__, #__view_cls__

Methods included from TableMethods

#==, #_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



51
52
53
54
55
56
# File 'lib/object_table/view.rb', line 51

def cache_columns(&block)
  @columns = columns
  value = block.call()
  @columns = nil
  value
end

#cache_indices(&block) ⇒ Object



40
41
42
43
44
45
# File 'lib/object_table/view.rb', line 40

def cache_indices(&block)
  @indices = indices
  value = block.call()
  @indices = nil
  value
end

#cloneObject



21
22
23
24
25
26
27
28
# File 'lib/object_table/view.rb', line 21

def clone
  if nrows == 0
    cols = @parent.columns.map{|k, v| [k, NArray.new(v.typecode, 0)]}
  else
    cols = @parent.columns.map{|k, v| [k, v[false, indices]]}
  end
  __table_cls__.new(cols)
end

#columnsObject



47
48
49
# File 'lib/object_table/view.rb', line 47

def columns
  @columns or super
end

#indicesObject



36
37
38
# File 'lib/object_table/view.rb', line 36

def indices
  @indices or NArray.int(@parent.nrows).indgen![@parent._apply_block &@filter]
end

#inspect(*args) ⇒ Object



30
31
32
33
34
# File 'lib/object_table/view.rb', line 30

def inspect(*args)
  cache_columns{ super }
rescue NoMethodError => e
  raise Exception.new(e)
end

#make_viewObject



17
18
19
# File 'lib/object_table/view.rb', line 17

def make_view
  __static_view_cls__.new @parent, indices
end