Class: ObjectTable::View

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ViewMethods
Defined in:
lib/object_table/view.rb

Constant Summary collapse

Util =
ObjectTable::Util

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 TableMethods

#==, #_get_sort_index, #apply, #each_row, #group_by, #method_missing, #ncols, #nrows, #respond_to?, #set_column, #sort_by, #where

Methods included from Stacking

process_stackable_grid, #stack, stack_segments

Methods included from Joining

copy_column, #join

Methods included from Printing

calc_column_widths, format_column, format_rows, format_section, split_column_lines

Constructor Details

#initialize(parent, &block) ⇒ View

Returns a new instance of View.



13
14
15
16
17
# File 'lib/object_table/view.rb', line 13

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_columnsObject



53
54
55
56
57
58
# File 'lib/object_table/view.rb', line 53

def cache_columns
  @columns = columns
  value = yield
  @columns = nil
  value
end

#cache_indicesObject



42
43
44
45
46
47
# File 'lib/object_table/view.rb', line 42

def cache_indices
  @indices = indices
  value = yield
  @indices = nil
  value
end

#cloneObject



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

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



49
50
51
# File 'lib/object_table/view.rb', line 49

def columns
  @columns or super
end

#indicesObject



38
39
40
# File 'lib/object_table/view.rb', line 38

def indices
  @indices or NArray.int(@parent.nrows).indgen![Util.apply_block(@parent, @filter)]
end

#inspect(*args) ⇒ Object



32
33
34
35
36
# File 'lib/object_table/view.rb', line 32

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

#make_viewObject



19
20
21
# File 'lib/object_table/view.rb', line 19

def make_view
  __static_view_cls__.new @parent, indices
end