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, :split => "_" }
Instance Attribute Summary
Attributes included from Unary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, operand, options = {}) ⇒ Autowrap
constructor
A new instance of Autowrap.
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_json, #update, #visit, #with_typecheck, #without_typecheck, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #matching, #not_matching, #page, #project, #rename, #restrict, #spied, #union, #unspied
Methods included from Algebra::Shortcuts
Constructor Details
#initialize(type, operand, options = {}) ⇒ Autowrap
Returns a new instance of Autowrap.
28 29 30 31 32 33 34 |
# File 'lib/bmg/operator/autowrap.rb', line 28 def initialize(type, operand, = {}) @type = type @operand = operand = = DEFAULT_OPTIONS.merge() [:postprocessor] = NoLeftJoinNoise.new([:postprocessor]) end |
Instance Method Details
#each ⇒ Object
42 43 44 45 46 |
# File 'lib/bmg/operator/autowrap.rb', line 42 def each @operand.each do |tuple| yield autowrap_tuple(tuple) end end |
#to_ast ⇒ Object
48 49 50 |
# File 'lib/bmg/operator/autowrap.rb', line 48 def to_ast [ :autowrap, operand.to_ast, .dup ] end |