Class: View

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rural.rb,
ext/vlerq_ext.c

Constant Summary collapse

Map =
Hash.new { |h,k| fail "Unknown view operator: #{k}" }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject



263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'ext/vlerq_ext.c', line 263

static VALUE view_initialize_keep (VALUE self, VALUE arg) {
  View_p view;
  Item item;
  PUSH_KEEP_REFS
  
  item.o = arg;
  if (!ObjToItem(IT_view, &item))
    Assert(0);
    
  DATA_PTR(self) = IncRefCount(item.v);
  
  POP_KEEP_REFS
  return self;
}

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



26
27
28
# File 'lib/rural.rb', line 26

def method_missing(m, *args)
  Vlerq.dispatch(Map[m], self, *args)
end

Class Method Details

.method_missing(m, *args) ⇒ Object



30
31
32
# File 'lib/rural.rb', line 30

def self.method_missing(m, *args)
  Vlerq.dispatch(Map[m], *args)
end

Instance Method Details

#dumpObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rural.rb', line 34

def dump 
  out = Array.new(3 + size, '')
  
  for cname, ctype in names.to_a.zip(types.to_a)
    values = [cname, '-']
    
    case ctype
    when 'B'
      each { |r| values << "#{r[cname].size}b" }
    when 'V'
      each { |r| values << "##{r[cname].size}" }
    else
      each { |r| values << r[cname].to_s }
    end

    widths = []
    values.each { |s| widths << s.size }
    w = [widths.max, 50].min
    right = /[BILFDV]/ =~ ctype
    fmt = "  %#{right ? '' : '-'}#{w}.#{w}s"

    values[0], values[1] = cname.ljust(w), ''.ljust(w, '-')
    values << values[1]
    values.each_with_index { |s,i| out[i] += fmt % s }
  end
  out.join "\n"
end

#eachObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'ext/vlerq_ext.c', line 330

static VALUE view_each_keep (VALUE self) {
  int r, rows;
  Item item;
  
  PUSH_KEEP_REFS
  
  item.o = self;
  if (!ObjToItem(IT_view, &item))
    Assert(0);
    
  rows = ViewSize(item.v);
  
  for (r = 0; r < rows; ++r)
    rb_yield(AtRow(self, r));

  POP_KEEP_REFS
  return self;
}

#project(*names) ⇒ Object



62
63
64
# File 'lib/rural.rb', line 62

def project(*names)
  colmap(names).unique
end