Skip to content

Instantly share code, notes, and snippets.

@oleander

oleander/e.rb Secret

Created September 1, 2015 20:39
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 oleander/7b988a4cfbfd3e07b642 to your computer and use it in GitHub Desktop.
Save oleander/7b988a4cfbfd3e07b642 to your computer and use it in GitHub Desktop.
require "pp"
data = "123. This is a question A Option One B Option two C Danke D Nope"
options = {}
("A".."D").to_a.reverse.each do |letter|
data, letter, option = data.split(/ (#{letter}) (.+?)$/, 3)
options[letter] = option
end
_, number, question = data.match(/^(\d+)\. (.+)$/).to_a
result = {
number: number,
question: question,
options: options
}
pp result
# {:number=>"123",
# :question=>"This is a question",
# :options=>{"D"=>"Nope", "C"=>"Danke", "B"=>"Option two", "A"=>"Option One"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment