Module: Observance
- Defined in:
- lib/observance.rb,
lib/observance/version.rb
Defined Under Namespace
Classes: Observation
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.run(*observations) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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| = (obs.inject(0) do |acc, o| acc = acc + c.similarity_to(o) end).fdiv(obs.size) Observation.new(.round(4), observations[index], index) end.sort end |