Class: Purview::Tables::Base
- Includes:
- Mixins::Helpers, Mixins::Logger
- Defined in:
- lib/purview/tables/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#database ⇒ Object
Returns the value of attribute database.
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #column_names ⇒ Object
- #columns_by_name ⇒ Object
- #columns_by_source_name ⇒ Object
-
#initialize(name, opts = {}) ⇒ Base
constructor
A new instance of Base.
Methods included from Mixins::Logger
#logger, #logger_opts, #logger_type, #with_context_logging
Methods included from Mixins::Helpers
#blank?, #coalesced, #filter_blank_values, #filter_nil_values, #present?, #timestamp, #with_timestamp, #zero?
Constructor Details
#initialize(name, opts = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/purview/tables/base.rb', line 6 def initialize(name, opts={}) @name = name.to_sym @opts = opts @database = database_opt @columns = Set.new.tap do |result| (default_columns + columns_opt).each do |column| column.table = self if result.add?(column) end end @indices = Set.new.tap do |result| (default_indices + indices_opt).each do |index| index.table = self if result.add?(index) end end end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/purview/tables/base.rb', line 4 def columns @columns end |
#database ⇒ Object
Returns the value of attribute database.
4 5 6 |
# File 'lib/purview/tables/base.rb', line 4 def database @database end |
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
4 5 6 |
# File 'lib/purview/tables/base.rb', line 4 def indices @indices end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/purview/tables/base.rb', line 4 def name @name end |
Instance Method Details
#column_names ⇒ Object
22 23 24 |
# File 'lib/purview/tables/base.rb', line 22 def column_names columns.map(&:name) end |
#columns_by_name ⇒ Object
26 27 28 29 30 31 |
# File 'lib/purview/tables/base.rb', line 26 def columns_by_name columns.reduce({}) do |memo, column| memo[column.name] = column memo end end |
#columns_by_source_name ⇒ Object
33 34 35 36 37 38 |
# File 'lib/purview/tables/base.rb', line 33 def columns_by_source_name columns.reduce({}) do |memo, column| memo[column.source_name] = column memo end end |