class GreenMidget::Examples

Constants

GENERAL_FEATURE_NAME

Public Class Methods

[](feature) click to toggle source
Calls superclass method GreenMidget::Countable::[]
# File lib/green_midget/models/examples.rb, line 19
def self.[](feature)
  object = super(feature)

  if object.no_examples? && (feature == GENERAL_FEATURE_NAME)
    raise NoExamplesGiven
  elsif object.no_examples?
    super GENERAL_FEATURE_NAME
  else
    object
  end
end
log_ratio() click to toggle source
# File lib/green_midget/models/examples.rb, line 36
def self.log_ratio
  self[GENERAL_FEATURE_NAME].log_ratio
end
objects(features, with_general = false) click to toggle source
Calls superclass method GreenMidget::Countable::objects
# File lib/green_midget/models/examples.rb, line 31
def self.objects(features, with_general = false)
  features += with_general ? [ GENERAL_FEATURE_NAME ] : []
  super(features)
end
total() click to toggle source
# File lib/green_midget/models/examples.rb, line 40
def self.total
  @@total ||= self[GENERAL_FEATURE_NAME].total
end

Public Instance Methods

no_examples?() click to toggle source
# File lib/green_midget/models/examples.rb, line 52
def no_examples?
  CATEGORIES.inject(1) { |memo, category| memo *= self[category] } == 0
end
probability_for(category) click to toggle source
# File lib/green_midget/models/examples.rb, line 44
def probability_for(category)
  self[category] / total
end
total() click to toggle source
# File lib/green_midget/models/examples.rb, line 48
def total
  CATEGORIES.inject(0) { |memo, category| memo += self[category] }
end