Class: Csb::Cols

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/csb/cols.rb,
lib/csb/testing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Cols

Returns a new instance of Cols.

Yields:

  • (_self)

Yield Parameters:

  • _self (Csb::Cols)

    the object that the method was called on



10
11
12
13
# File 'lib/csb/cols.rb', line 10

def initialize
  @cols = []
  yield(self) if block_given?
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



8
9
10
# File 'lib/csb/cols.rb', line 8

def cols
  @cols
end

Instance Method Details

#add(*args, &block) ⇒ Object



23
24
25
# File 'lib/csb/cols.rb', line 23

def add(*args, &block)
  cols << Col.new(*args, &block)
end

#as_table(items) ⇒ Object



7
8
9
# File 'lib/csb/testing.rb', line 7

def as_table(items)
  [headers] + items.map { |item| values(item) }
end

#col_pairs(item) ⇒ Object



3
4
5
# File 'lib/csb/testing.rb', line 3

def col_pairs(item)
  headers.zip(values(item))
end

#copy!(other) ⇒ Object



15
16
17
# File 'lib/csb/cols.rb', line 15

def copy!(other)
  @cols = other.cols.deep_dup
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/csb/cols.rb', line 19

def each(&block)
  cols.each(&block)
end

#headersObject



27
28
29
# File 'lib/csb/cols.rb', line 27

def headers
  map(&:name)
end

#values_by_item(item) ⇒ Object Also known as: values



31
32
33
34
35
# File 'lib/csb/cols.rb', line 31

def values_by_item(item)
  map do |col|
    col.value_by_item(item)
  end
end