Class: Dill::TextTable
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Conversions, Enumerable
- Defined in:
- lib/dill/text_table.rb,
lib/dill/text_table/mapping.rb,
lib/dill/text_table/cell_text.rb,
lib/dill/text_table/void_mapping.rb,
lib/dill/text_table/transformations.rb
Defined Under Namespace
Modules: Transformations
Classes: CellText, Mapping, VoidMapping
Class Method Summary
collapse
Instance Method Summary
collapse
#Boolean, #List, #Timeish
Constructor Details
#initialize(table) ⇒ TextTable
Returns a new instance of TextTable.
74
75
76
|
# File 'lib/dill/text_table.rb', line 74
def initialize(table)
self.table = table
end
|
Class Method Details
.Array(table) ⇒ Object
9
10
11
|
# File 'lib/dill/text_table.rb', line 9
def Array(table)
new(table).to_a
end
|
.Hash(table) ⇒ Object
13
14
15
|
# File 'lib/dill/text_table.rb', line 13
def Hash(table)
new(table).to_h
end
|
.map(name, options = {}, &block) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/dill/text_table.rb', line 17
def map(name, options = {}, &block)
case name
when :*
set_default_mapping options, &block
else
set_mapping name, options, &block
end
end
|
.mappings ⇒ Object
26
27
28
29
30
|
# File 'lib/dill/text_table.rb', line 26
def mappings
@mappings ||= Hash.
new { |h, k| h[k] = Mapping.new }.
merge(with_parent_mappings)
end
|
.skip(name) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/dill/text_table.rb', line 32
def skip(name)
case name
when :*
set_default_mapping VoidMapping
else
raise ArgumentError, "can't convert #{name.inspect} to name"
end
end
|
Instance Method Details
#each(&block) ⇒ Object
78
79
80
|
# File 'lib/dill/text_table.rb', line 78
def each(&block)
rows.each(&block)
end
|
#rows ⇒ Object
Also known as:
to_a
82
83
84
|
# File 'lib/dill/text_table.rb', line 82
def rows
@rows ||= table.hashes.map { |h| new_row(h) }
end
|
#single_row ⇒ Object
Also known as:
to_h
86
87
88
|
# File 'lib/dill/text_table.rb', line 86
def single_row
@single_row ||= new_row(table.rows_hash)
end
|