Class: ObjectTable::Column
- Inherits:
-
NArray
- Object
- NArray
- ObjectTable::Column
show all
- Defined in:
- lib/object_table/column.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
58
59
60
|
# File 'lib/object_table/column.rb', line 58
def method_missing(*args)
collect{|x| x.send(*args)}
end
|
Class Method Details
.make(value) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/object_table/column.rb', line 5
def self.make(value)
value = case value
when self
value
when NArray
if value.rank <= 0
self.new(value.typecode, 0)
else
cast(value)
end
when Range
to_na(value.to_a)
when Array
to_na(value)
else
raise ArgumentError.new("Expected NArray or Array, got #{value.class}")
end
value
end
|
Instance Method Details
#[](*a) ⇒ Object
29
30
31
32
|
# File 'lib/object_table/column.rb', line 29
def [](*a)
result = super
result.is_a?(NArray) ? self.class.make(result) : result
end
|
#[]=(*args) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/object_table/column.rb', line 34
def []=(*args)
if (args[-1].is_a?(Array) or args[-1].is_a?(NArray)) and args[-1].empty? and self.empty?
return args[-1]
end
super
end
|
#_refer(value) ⇒ Object
def collect(*)
self.class.make super, name
end
66
67
68
|
# File 'lib/object_table/column.rb', line 66
def _refer(value)
value.is_a?(NArray) ? NArray.refer(value) : value
end
|
#coerce_rev(other, operator) ⇒ Object
54
55
56
|
# File 'lib/object_table/column.rb', line 54
def coerce_rev(other, operator)
other.send(operator, NArray.refer(self))
end
|
#slice ⇒ Object
25
26
27
|
# File 'lib/object_table/column.rb', line 25
def slice(*)
self.class.make super
end
|
#stack(*others) ⇒ Object
%w{ not abs -@ ~ }.each do |op|
define_method(op) do
self.class.make super()
# end
end
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/object_table/column.rb', line 89
def stack(*others)
columns = [self] + others
new_rows = columns.map{|x| x.shape[-1]}.reduce(:+)
new_col = self.class.new(typecode, *shape[0...-1], new_rows)
padding = [nil] * (rank - 1)
row = 0
columns.each do |col|
new_col[*padding, row ... (row + col.shape[-1])] = col
row += col.shape[-1]
end
new_col
end
|
#to_bool ⇒ Object
46
47
48
|
# File 'lib/object_table/column.rb', line 46
def to_bool
map{|i| i ? 1 : 0}.to_type('byte')
end
|
#to_object ⇒ Object
42
43
44
|
# File 'lib/object_table/column.rb', line 42
def to_object
to_type('object')
end
|
#uniq ⇒ Object
50
51
52
|
# File 'lib/object_table/column.rb', line 50
def uniq
self.class.make to_a.uniq
end
|