class FlatKit::StatType
Public Class Methods
for(type)
click to toggle source
# File lib/flat_kit/stat_type.rb, line 15 def self.for(type) return OrdinalStats if ordinal_types.include?(type) return NominalStats if nominal_types.include?(type) return NumericalStats if numerical_types.include?(type) raise ArgumentError, "Unknown stat type for #{type}" end
nominal_types()
click to toggle source
# File lib/flat_kit/stat_type.rb, line 3 def self.nominal_types [FieldType::BooleanType, FieldType::StringType, FieldType::NullType ] end
numerical_types()
click to toggle source
# File lib/flat_kit/stat_type.rb, line 11 def self.numerical_types [FieldType::FloatType, FieldType::IntegerType] end
ordinal_types()
click to toggle source
# File lib/flat_kit/stat_type.rb, line 7 def self.ordinal_types [FieldType::DateType, FieldType::TimestampType] end
Public Instance Methods
collected_stats()
click to toggle source
# File lib/flat_kit/stat_type.rb, line 22 def collected_stats raise NotImplementedError, "#{self.class.name} must implement #collected_stats" end
to_hash → Hash
click to toggle source
to_hash( %w[ count max mean ]) → Hash
return a hash of the stats. By default this returns a hash of all stats but passing in an array of items will limit the stats returned to only those in the Array.
If passed in an empty array or nil to to_hash
then STATS is assumed to be the list of stats to return in the hash.
# File lib/flat_kit/stat_type.rb, line 38 def to_hash( *args ) h = {} args = [ args ].flatten args = self.collected_stats if args.empty? args.each do |meth| h[meth] = self.send( meth ) end return h end
to_json → String
click to toggle source
to_json( *args ) → String
return a json string of the stats. By default this returns a json string of all the stats. If an array of items is passed in, those that match the known stats will be all that is included in the json output.
# File lib/flat_kit/stat_type.rb, line 57 def to_json( *args ) h = to_hash( *args ) Oj.dump(h) end