Class: Bmg::Operator::Autowrap::NoLeftJoinNoise
- Inherits:
-
Object
- Object
- Bmg::Operator::Autowrap::NoLeftJoinNoise
- Defined in:
- lib/bmg/operator/autowrap.rb
Overview
Removes the noise generated by left joins that were not join.
i.e. x is removed in { x: { id: nil, name: nil, … } }
Supported heuristics are:
-
nil: { x: { id: nil, name: nil, … } } => { x: nil }
-
delete: { x: { id: nil, name: nil, … } } => { }
-
none: { x: { id: nil, name: nil, … } } => { x: { id: nil, name: nil, … } }
-
a Hash, specifying a specific heuristic by tuple attribute
-
a Proc, ‘->(tuple,key){ … }` that affects the tuple manually
Constant Summary collapse
- REMOVERS =
{ nil: ->(t,k){ t[k] = nil }, delete: ->(t,k){ t.delete(k) }, none: ->(t,k){ t } }
Instance Attribute Summary collapse
-
#remover ⇒ Object
readonly
Returns the value of attribute remover.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #all_nil?(tuple) ⇒ Boolean
- #call(tuple) ⇒ Object
- #hash ⇒ Object
-
#initialize(remover) ⇒ NoLeftJoinNoise
constructor
A new instance of NoLeftJoinNoise.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
#initialize(remover) ⇒ NoLeftJoinNoise
Returns a new instance of NoLeftJoinNoise.
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/bmg/operator/autowrap.rb', line 195 def initialize(remover) @remover_to_s = remover @remover = case remover when NilClass then REMOVERS[:none] when Proc then remover when Symbol then REMOVERS[remover] when Hash then ->(t,k){ REMOVERS[remover[k] || :none].call(t,k) } else raise "Invalid remover `#{remover}`" end end |
Instance Attribute Details
#remover ⇒ Object (readonly)
Returns the value of attribute remover.
206 207 208 |
# File 'lib/bmg/operator/autowrap.rb', line 206 def remover @remover end |
Class Method Details
.new(remover) ⇒ Object
190 191 192 193 |
# File 'lib/bmg/operator/autowrap.rb', line 190 def self.new(remover) return remover if remover.is_a?(NoLeftJoinNoise) super end |
Instance Method Details
#==(other) ⇒ Object
230 231 232 |
# File 'lib/bmg/operator/autowrap.rb', line 230 def ==(other) other.is_a?(NoLeftJoinNoise) && remover.eql?(other.remover) end |
#all_nil?(tuple) ⇒ Boolean
216 217 218 219 |
# File 'lib/bmg/operator/autowrap.rb', line 216 def all_nil?(tuple) return false unless tuple.is_a?(Hash) tuple.all?{|(k,v)| v.nil? || all_nil?(tuple[k]) } end |
#call(tuple) ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/bmg/operator/autowrap.rb', line 208 def call(tuple) tuple.each_key do |k| call(tuple[k]) if tuple[k].is_a?(Hash) @remover.call(tuple, k) if tuple[k].is_a?(Hash) && all_nil?(tuple[k]) end tuple end |
#hash ⇒ Object
226 227 228 |
# File 'lib/bmg/operator/autowrap.rb', line 226 def hash remover.hash end |
#inspect ⇒ Object Also known as: to_s
221 222 223 |
# File 'lib/bmg/operator/autowrap.rb', line 221 def inspect @remover_to_s.inspect end |