-
-
Save practicingruby/4566418 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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