Created
October 8, 2010 13:11
-
-
Save aalin/616760 to your computer and use it in GitHub Desktop.
Prints the menu from restaurangbellevue.se
This file contains 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
#!/usr/bin/env ruby | |
require 'iconv' | |
require 'open-uri' | |
class String | |
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white] | |
def colorize(color) | |
value = case color | |
when Symbol | |
COLORS.index(color) || 0 | |
else | |
color | |
end | |
"\e[3#{ value }m#{ self }\e[0m" | |
end | |
end | |
raw_menu = open("http://www.restaurangbellevue.se/meny/V%20#{ Time.now.strftime('%W') }%2010.DOC").read | |
raw_menu.gsub!(/.*\000Restaurang\rBellevue\r/, '') | |
raw_menu.gsub!(/\000.*/, '') | |
raw_menu.gsub!(/\r/, "\n") | |
raw_menu = Iconv.iconv('utf-8', 'latin1', raw_menu).first | |
puts <<TITLE | |
__ __ __ | |
| |--.-----.| | |.-----.--.--.--.--.-----. | |
| _ | -__|| | || -__| | | | | -__| | |
|_____|_____||__|__||_____|\\___/|_____|_____| | |
TITLE | |
puts raw_menu.inspect | |
date_and_price = raw_menu.match(/Lunch meny\s+(\d+\s*\w*)\s+-\s+(\d+\s*\w+)\s+Kr (\d+)/) | |
puts "Lunchmeny %s-%s, pris: %d kr" % date_and_price.captures | |
puts | |
raw_menu.scan(/(Måndag|Tisdag|Onsdag|Torsdag|Fredag)\.?\n(.*?)\n\n/m).each do |day, foods| | |
puts day.colorize(:yellow) | |
food_lines = foods.split(/\n/).map(&:strip).reject(&:empty?) | |
color = nil | |
food_lines.each do |food| | |
case food | |
when /^(A|À) la carte/ | |
color = :red | |
when /^Veg: (.*)/ | |
puts $1.colorize(:green) | |
else | |
puts color ? food.colorize(color) : food | |
end | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment