Scientific Analysis

This program demonstrates the majority of ruby basics. It was fairly fun to make. It’s nothing too fancy. 
- modules
- classes
- mixins
- various methods
- modifying data structures
- instantiating objects
- testing via minitest gem

=begin
Your research team wants an application that will allow them to start tracking the results that are coming through the lab. You are interested in entries below zero (degrees Celsius).
Program Name: Scientific Analysis
Author: AGL
Brief Description:
Program take input three inputs researcher data, along with researcher
name and date. Then finds matching entry data type (below zero)
=end
# Require statements
require ‘minitest/autorun’
# Module Definition
module Analyze
def any_results_below_freezing?(hash)
hash.keys do |key|
result_below_freezing?(value) ? true : false
end
end

private
  def result_below_freezing?(element)
element < 0 ? true : false
end
end
# Class Definition
class CollectedData
# Mixin Module
include Analyze
attr_accessor :researcher_name, :date_entered, :data
def initialize(researcher_name, data_entered = Time.now)
@researcher_name = researcher_name
@date_entered = date_entered
@data = {}
end
def add(value)
@data = value
end
end
# Main Program Section
mydata = CollectedData.new(' Matt White')
mydata.add('boiling water' => 100, 'frying pan' => -75, 'pencil' => 20, 'diamond' => -10)
results = mydata.any_results_below_freezing?(mydata.data)
flatten_array = mydata.data.to_a.flatten
puts "Hello #{mydata.researcher_name}, the program is starting."
puts 'Here are the results.'
x = 0
y = 1
results.each do |result|
puts "#{flatten_array[x].capitalize} at #{flatten_array[y]} degrees is below zero: #{result}"
x += 2
y += 2
end
# Testing Code Section
class TestCollectedData < MiniTest::Unit::TestCase
def setup
@cd = CollectedData.new('John Smith')
@cd.add('IceBerg1' => -5, 'Deep freeze1' => -10, 'Driveway' => 35)
end
  def test_below_freezing
assert_equal [true, true, false],
@cd.any_results_below_freezing?(@cd.data)
end
end
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.