Commit 62282bbc authored by Coraline Ehmke's avatar Coraline Ehmke

More tests, better matching

parent 80a4cf43
......@@ -23,7 +23,8 @@ module Snuffle
elements.to_a.each do |outer_element|
cohort = Cohort.new(element: outer_element)
next unless cohort.values.count > 1
cohort.neighbors = nodes_with_parent(outer_element.node.parent_id).map do |sibling|
siblings = nodes.by_type(outer_element.node.type).to_a
cohort.neighbors = siblings.map do |sibling|
next unless inner_element = Element::Hash.materialize([sibling]).first
print "."
neighbor = cohort.neighbor.new(
......@@ -49,9 +50,7 @@ module Snuffle
Element::String.materialize(self.nodes.where(type: :dstr).to_a.compact)
end
def nodes_with_parent(parent_id)
self.nodes.where(parent_id: parent_id).to_a
end
end
......
......@@ -10,6 +10,7 @@ module Snuffle
scope :by_id, lambda{|id| where(:id => id)}
scope :by_type, lambda{|type| where(:type => type) }
scope :hashes, {type: :hash}
scope :with_parent, lambda{|parent_id| where(parent_id: parent_id) }
def self.nil
new(type: :nil)
......
......@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "poro_plus"
spec.add_dependency "rouge"
spec.add_dependency "text-table"
spec.add_dependency "haml"
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
......
......@@ -2,7 +2,13 @@ class Customer
attr_accessor :customer_id, :customer_name, :company_name
attr_accessor :street_address_1, :street_address_2
attr_accessor :city, :state, :postal_code
# attr_accessor :city, :state, :postal_code
MY_CONSTANT = "TheOtherZachIsThePrimaryZach"
def my_condition
puts "MAGIC" if true == false
end
def address_is_residence?
self.company_name.nil?
......@@ -13,7 +19,7 @@ class Customer
end
def neighborhood
fake_neighborhood_api_call(state: self.state, city: self.city, postal_code: self.postal_code)
# make_neighborhood_api_call(state: self.state, city: self.city, postal_code: self.postal_code)
end
def something_else
......@@ -54,7 +60,7 @@ class Customer
string << self.company_name if address_is_residence?
string << self.street_address_1
string << self.street_address_2 if street_address_2.present?
string << "#{self.city}, #{self.state} #{self.postal_code}"
# string << "#{self.city}, #{self.state} #{self.postal_code}"
string.join", "
end
......
# Should only match name, business
class Customer
attr_accessor :customer_id, :customer_name, :company_name
attr_accessor :street_address_1, :street_address_2
attr_accessor :city, :state, :postal_code
MY_CONSTANT = "TheOtherZachIsThePrimaryZach"
def my_condition
puts "MAGIC" if true == false
end
def address_is_residence?
self.company_name.nil?
end
def get_coords_for_address
fake_api_call(city: city, state: state, postal_code: postal_code)
end
def neighborhood
# make_neighborhood_api_call(state: self.state, city: self.city, postal_code: self.postal_code)
end
def something_else
fake_neighborhood_api_call(city: self.city, state: self.state)
end
def and_something_else_again
fake_neighborhood_api_call(city: self.city)
end
def and_something_else_again_and_again
fake_neighborhood_api_call(state: self.state)
end
def fake_neighborhood_api_call(args={})
"Probably River North"
end
def fake_api_call(args={})
[112.32, 124.11]
end
def business_card_api_call
{name: customer_name, business: company_name}
end
def letterhead_api_call
{name: customer_name, business: company_name}
end
def letterhead
"#{customer_name}\r#{company_name}"
end
def address
string = ""
string << self.customer_name
string << self.company_name if address_is_residence?
string << self.street_address_1
string << self.street_address_2 if street_address_2.present?
# string << "#{self.city}, #{self.state} #{self.postal_code}"
string.join", "
end
end
\ No newline at end of file
require 'spec_helper'
require 'pry'
describe Snuffle::CohortDetector do
describe Snuffle::SourceFile do
let(:file) { File.read("spec/fixtures/program_2.rb") }
let(:parser) { Snuffle::FileParser.new(file) }
let(:detector) { Snuffle::CohortDetector.new(parser.hashes) }
let(:source_file) {Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_2.rb") }
let(:source_file_2) {Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_3.rb") }
describe "weighting" do
......@@ -13,7 +12,22 @@ describe Snuffle::CohortDetector do
# E.g. [city, state]
context "a hash cohort" do
it "is detected" do
# Example Case: hash hit with attr_accessor match
# Fixture file contains two instances of city, postal_code, state
# One is args to attr_accessor, one is args hash to method
it "does not match hash values with non-hash values" do
attr_accessor_args = ['city', 'postal_code', 'state']
values = source_file.summary.object_candidates
expect(values.include?(attr_accessor_args)).to be_falsey
end
it "matches elements with different parents" do
args = ['company_name', 'customer_name']
values = source_file.summary.object_candidates
expect(values.include?(args)).to be_truthy
end
xit "is detected" do
expect(detector.cohorts.map(&:values)).to eq(
[
[:city, :postal_code, :state],
......
require 'snuffle'
def file_parser
@file_parser ||= Snuffle::FileParser.new(File.open("spec/fixtures/program_2.rb", "r").read)
end
def hash_clump
@hash_clump ||= Snuffle::CohortDetector.new(file_parser.hashes)
end
def string_clump
@string_clump ||= Snuffle::CohortDetector.new(file_parser.strings)
end
\ No newline at end of file
end
def source_file
@source_file ||= Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_2.rb")
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment