Skip to content

Instantly share code, notes, and snippets.

@chrislo
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislo/e3c8d495c96659ef1936 to your computer and use it in GitHub Desktop.
Save chrislo/e3c8d495c96659ef1936 to your computer and use it in GitHub Desktop.
FuzzyMatch Courses
require 'fuzzy_match'
require 'date'
require 'ostruct'
haystack = [
OpenStruct.new(
title: "Good brain, bad brain: Parkinson's disease",
start: Date.parse('24 February 2014'),
slug: 'good-brain-bad-brain-parks'),
OpenStruct.new(
title: "Archaeology of Portus: exploring the lost harbour of ancient Rome",
start: Date.parse('19 May 2014'),
slug: 'portus'),
OpenStruct.new(
title: "The secret power of brands",
start: Date.parse('24 February 2014'),
slug: 'secret-power-of-brands-2014'),
OpenStruct.new(
title: "The secret power of brands",
start: Date.parse('14 October 2013'),
slug: 'secret-power-of-brands')
]
survey_creation_date = Date.parse('20 February 2014')
filtered_haystack = haystack.reject { |course| course.start < survey_creation_date }
matcher = FuzzyMatch.new(filtered_haystack, read: :title)
matcher.find('The secret power of brands: pre-course survey')
# => #<OpenStruct title="The secret power of brands", start=#<Date: 2014-02-24 ((2456713j,0s,0n),+0s,2299161j)>, slug="secret-power-of-brands-2014">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment