Sha256: c655e75c6eb6e2d298c8cac2e80c4fe2f2c4fccf1080e4037f3765b34693d427
Contents?: true
Size: 1.74 KB
Versions: 2
Compression:
Stored size: 1.74 KB
Contents
module Alf module Types # # Encapsulates a Summarization information # class Summarization # @return [Hash] the hash of aggregations, AttrName -> Aggregators attr_reader :aggregations # # Creates a Summarization instance # # @param [Hash] aggs, aggregations as a mapping AttrName -> Aggregators # def initialize(aggs) @aggregations = aggs end # # Coerces `arg` to an Aggregator # def self.coerce(arg) case arg when Summarization arg when Array coerce(Hash[*arg]) when Hash h = Tools.tuple_collect(arg) do |k,v| [Tools.coerce(k, AttrName), Tools.coerce(v, Aggregator)] end Summarization.new(h) else raise ArgumentError, "Invalid arg `#{arg}` for Summarization()" end end def self.from_argv(argv, opts = {}) coerce(argv) end # # Computes the least tuple # def least Tools.tuple_collect(@aggregations){|k,v| [k, v.least] } end # # Computes the resulting aggregation from aggs if tuple happens. # def happens(aggs, tuple) Tools.tuple_collect(@aggregations){|k,v| [k, v.happens(aggs[k], tuple)] } end # # Finalizes the summarization `aggs` # def finalize(aggs) Tools.tuple_collect(@aggregations){|k,v| [k, v.finalize(aggs[k])] } end def ==(other) other.is_a?(Summarization) && (other.aggregations == aggregations) end end # class Summarization end # module Types end # module Alf
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
alf-0.10.1 | lib/alf/types/summarization.rb |
alf-0.10.0 | lib/alf/types/summarization.rb |