Sha256: a741c14695269a9ffb55b00ea97f018a389d577904aaaef18cf327e5e3d57d1e

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8

module Piglet
  module Relation
    class Split # :nodoc:
      include Relation
    
      def initialize(relation, interpreter, expressions)
        @sources, @interpreter, @expressions = [relation], interpreter, expressions
        @shard_map = create_shards
      end
    
      def shards
        @shard_map.values_at(*@expressions)
      end
    
      def to_s
        split_strings = @expressions.map do |expression|
          "#{@shard_map[expression].alias} IF #{expression}"
        end
        
        "SPLIT #{@sources.first.alias} INTO #{split_strings.join(', ')}"
      end
    
    private
  
      def create_shards
        @expressions.inject({}) do |map, expr|
          map[expr] = RelationShard.new(self, @interpreter)
          map
        end
      end
    end
  
    class RelationShard # :nodoc:
      include Relation
    
      def initialize(split, interpreter)
        @sources, @interpreter = [split], interpreter
      end
    
      def to_s
        self.alias
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piglet-0.3.0 lib/piglet/relation/split.rb