Class: Csb::Cols
- Inherits:
-
Object
- Object
- Csb::Cols
- Includes:
- Enumerable
- Defined in:
- lib/csb/cols.rb,
lib/csb/testing.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
Instance Method Summary collapse
- #add(*args, &block) ⇒ Object
- #as_table(items) ⇒ Object
- #col_pairs(item) ⇒ Object
- #copy!(other) ⇒ Object
- #each(&block) ⇒ Object
- #headers ⇒ Object
-
#initialize {|_self| ... } ⇒ Cols
constructor
A new instance of Cols.
- #values_by_item(item) ⇒ Object (also: #values)
Constructor Details
#initialize {|_self| ... } ⇒ Cols
Returns a new instance of Cols.
10 11 12 13 |
# File 'lib/csb/cols.rb', line 10 def initialize @cols = [] yield(self) if block_given? end |
Instance Attribute Details
#cols ⇒ Object (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 |
#headers ⇒ Object
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 |