Skip to content

Instantly share code, notes, and snippets.

@hukl
Last active December 16, 2015 13:06
Show Gist options
  • Save hukl/db788fe9ce30590bff27 to your computer and use it in GitHub Desktop.
Save hukl/db788fe9ce30590bff27 to your computer and use it in GitHub Desktop.
Blog post example for truth tables
# defining some constants
ARCHIVE_REQUESTED = 1 # binary 01
ARCHIVE_NOT_REQUESTED = 0 # binary 00
FINISHED_PROCESSING = 2 # binary 10
NOT_FINISHED_PROCESSING = 0 # binary 00
NOOP = 0 # binary 00
START = 1 # binary 01
BROKEN = 2 # binary 10
FINISHED = 3 # binary 11
def archive_requested?
if user.requested_archive == true
ARCHIVE_REQUESTED
else
ARCHIVE_NOT_REQUESTED
end
end
def finished_processing?(user_id)
if archiver.processing_state(user_id) == :finished
FINISHED_PROCESSING
else
NOT_FINISHED_PROCESSING
end
end
def archive_state(user)
result = archive_requested? | finished_processing?(user.id)
case result
when NOOP then nil
when START then archiver.start_processing(user.id)
when FINISHED then archiver.get_file(user.id)
when BROKEN then notify_engineers
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment