Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Last active December 11, 2015 07:28
Show Gist options
  • Select an option

  • Save practicingruby/4566418 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/4566418 to your computer and use it in GitHub Desktop.
module MyApplication
Conditions = {}
Conditions[:near_christmas] = FuzzyLogic::Set.new(1) { |time|
# default output is zero
o = 0.0
# time has to be in december before or at the 24th
if time.month == 12 and time.day <= 24 then
# set is completly true when its 20th december or above
o = 1.0 if time.day >= 20
# set is fuzzy when its between 6th and 19th
o = 1.0 - (24.0 - time.day)/(24.0 - 6.0) if time.day >= 6 and time.day < 20.0
end
# just the correct return
o
}
end
# somewhere else, you would require the above file and then run:
MyApplication::Conditions[:near_christmas].get(Time.now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment