Class: Bmg::Operator::Autowrap
- Inherits:
-
Object
- Object
- Bmg::Operator::Autowrap
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/autowrap.rb
Overview
Autowrap operator.
Autowrap can be used to structure tuples ala Tutorial D’ wrap, but it works with conventions instead of explicit wrapping, and supports multiple levels or wrapping.
Examples:
[{ a: 1, b_x: 2, b_y: 3 }] => [{ a: 1, b: { x: 2, y: 3 } }]
[{ a: 1, b_x_y: 2, b_x_z: 3 }] => [{ a: 1, b: { x: { y: 2, z: 3 } } }]
Autowrap supports the following options:
-
‘postprocessor: :nil|:none|:delete|Hash|Proc` see NoLeftJoinNoise
-
‘split: String` the seperator to use to split keys, defaults to `_`
Defined Under Namespace
Modules: Support Classes: NoLeftJoinNoise
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :postprocessor => :none, :postprocessor_condition => :all, :split => "_" }
Instance Attribute Summary
Attributes included from Bmg::Operator
Class Method Summary collapse
Instance Method Summary collapse
- #_count ⇒ Object
- #each ⇒ Object
-
#initialize(type, operand, options = {}) ⇒ Autowrap
constructor
A new instance of Autowrap.
- #same_options?(opts) ⇒ Boolean
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, operand, options = {}) ⇒ Autowrap
Returns a new instance of Autowrap.
35 36 37 38 39 40 |
# File 'lib/bmg/operator/autowrap.rb', line 35 def initialize(type, operand, = {}) @type = type @operand = operand @original_options = @options = () end |
Class Method Details
.separator(options) ⇒ Object
30 31 32 |
# File 'lib/bmg/operator/autowrap.rb', line 30 def separator() [:split] || DEFAULT_OPTIONS[:split] end |
Instance Method Details
#_count ⇒ Object
65 66 67 |
# File 'lib/bmg/operator/autowrap.rb', line 65 def _count operand._count end |
#each ⇒ Object
52 53 54 55 56 57 |
# File 'lib/bmg/operator/autowrap.rb', line 52 def each return to_enum unless block_given? @operand.each do |tuple| yield autowrap_tuple(tuple) end end |
#same_options?(opts) ⇒ Boolean
48 49 50 |
# File 'lib/bmg/operator/autowrap.rb', line 48 def (opts) (opts) == end |
#to_ast ⇒ Object
59 60 61 |
# File 'lib/bmg/operator/autowrap.rb', line 59 def to_ast [ :autowrap, operand.to_ast, @original_options.dup ] end |