module Observance

Constants

Observation
VERSION

Public Class Methods

run(*observations) click to toggle source
# File lib/observance.rb, line 18
def self.run(*observations)
  obs = if observations.first.is_a? Array
          wrapped_in_hashes(observations)
        elsif observations.first.respond_to? :to_h
          observations.map(&:to_h)
        else
          raise "Observations need to be Array or respond to 'to_h'"
        end
  obs.each_with_index.map do |c, index|
    rating = (obs.inject(0) do |acc, o|
      acc = acc + c.similarity_to(o)
    end).fdiv(obs.size)
    Observation.new(rating.round(4), observations[index], index)
  end.sort
end

Private Class Methods

wrapped_in_hashes(observations) click to toggle source
# File lib/observance.rb, line 36
def self.wrapped_in_hashes(observations)
  observations.map do |o| 
    Hash[(0...o.size).zip(o)]
  end
end