Class: Omen::Combination
- Inherits:
-
Object
- Object
- Omen::Combination
- Defined in:
- app/models/omen/combination.rb
Overview
One column a reply asks to be drawn as its parts joined, where the database could not join them.
Constant Summary collapse
- SCHEMA =
All a reply may declare: a name, the headers to join, and what goes between them.
{ type: 'array', description: 'Columns to draw as one, where the database could not build the value itself ' \ 'because a part of it is encrypted. Empty where nothing needs joining.', items: { type: 'object', additionalProperties: false, required: %w[ name parts separator ], properties: { name: { type: 'string', description: 'The header the joined column is drawn under.' }, parts: { type: 'array', items: { type: 'string' }, description: 'Headers of your own query to join, in the order they read.', }, separator: { type: 'string', description: 'What goes between them, such as ", ".' }, }, }, }
Class Method Summary collapse
-
.all(declared, headers) ⇒ Array<Omen::Combination>
The ones a row can be drawn through.
Instance Method Summary collapse
-
#applied(row) ⇒ Hash
Joins what Omen::Column#read handed back, less the blanks: HIDDEN is a value, NULL is not.
-
#initialize(declared) ⇒ Combination
constructor
A new instance of Combination.
-
#over?(headers) ⇒ Boolean
Answered rather than raised on: the rows are right, and only the presentation was wrong.
Constructor Details
#initialize(declared) ⇒ Combination
Returns a new instance of Combination.
27 28 29 |
# File 'app/models/omen/combination.rb', line 27 def initialize(declared) @declared = declared end |
Class Method Details
.all(declared, headers) ⇒ Array<Omen::Combination>
Returns the ones a row can be drawn through.
22 23 24 |
# File 'app/models/omen/combination.rb', line 22 def self.all(declared, headers) declared.map { |one| new one }.select { |combination| combination.over? headers } end |
Instance Method Details
#applied(row) ⇒ Hash
Joins what Omen::Column#read handed back, less the blanks: HIDDEN is a value, NULL is not.
39 40 41 42 43 44 45 46 47 |
# File 'app/models/omen/combination.rb', line 39 def applied(row) row.each_with_object({}) do |(header, value), into| if header == parts.first into[name] = parts.filter_map { |part| row[part].presence }.join separator elsif parts.exclude? header into[header] = value end end end |
#over?(headers) ⇒ Boolean
Answered rather than raised on: the rows are right, and only the presentation was wrong.
34 |
# File 'app/models/omen/combination.rb', line 34 def over?(headers) = parts.any? && parts.all? { |part| headers.include? part } |