Class: ROM::SQL::Header
- Inherits:
-
Object
- Object
- ROM::SQL::Header
- Defined in:
- lib/rom/sql/header.rb
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#initialize(columns, table) ⇒ Header
constructor
A new instance of Header.
- #prefix(col_prefix) ⇒ Object
- #project(*names) ⇒ Object
- #qualified ⇒ Object
- #rename(options) ⇒ Object
- #to_ary ⇒ Object (also: #to_a)
- #to_h ⇒ Object
Constructor Details
#initialize(columns, table) ⇒ Header
Returns a new instance of Header.
11 12 13 14 |
# File 'lib/rom/sql/header.rb', line 11 def initialize(columns, table) super @table = table end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
9 10 11 |
# File 'lib/rom/sql/header.rb', line 9 def table @table end |
Instance Method Details
#prefix(col_prefix) ⇒ Object
48 49 50 |
# File 'lib/rom/sql/header.rb', line 48 def prefix(col_prefix) rename(Hash[map { |col| [col, :"#{col_prefix}_#{col}"] }]) end |
#project(*names) ⇒ Object
28 29 30 |
# File 'lib/rom/sql/header.rb', line 28 def project(*names) find_all { |col| names.include?(col) } end |
#qualified ⇒ Object
32 33 34 |
# File 'lib/rom/sql/header.rb', line 32 def qualified map { |col| :"#{table}__#{col}" } end |
#rename(options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rom/sql/header.rb', line 36 def rename() map { |col| new_name = [col] if new_name :"#{col}___#{new_name}" else col end } end |
#to_ary ⇒ Object Also known as: to_a
16 17 18 |
# File 'lib/rom/sql/header.rb', line 16 def to_ary columns end |
#to_h ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rom/sql/header.rb', line 21 def to_h columns.each_with_object({}) { |col, h| left, right = col.to_s.split('___') h[left.to_sym] = (right || left).to_sym } end |