Ordina puzzle in Ruby
Ordina is running a campaign to attract Java developers.
Here is my version of the puzzle in Ruby. For a better comparison I’ve kept some of the Java style code and refrained from some one liners. Still, it’s about half as long as the Java version. My solution to the puzzle uses wikipedia to lookup the acronyms.
ordina.rb
require 'open-uri'
module Nl
module Ordina
class JavaSpecialist
def self.main
js = find_specialist_wanna_be
if js
js.start
else
puts "Geen JavaSpecialist implementatie gevonden"
end
end
def start
report = "Volgens de specialist #{name}\x5c\x6eHebben de volgende termen de betekenis" +
"\x5c\x6e\x55\x4d\x4c #{eval "waarStaat\x55\x4d\x4cVoor" } \x5c\x6e\x52\x55\x50 " +
"#{eval "waarStaat\x52\x55\x50Voor" } \x5c\x6e\x58\x4d\x4c #{eval "waarStaat\x58\x4d\x4cVoor" } " +
"\x5c\x6e\x4d\x56\x43 #{eval "waarStaat\x4d\x56\x43Voor" } \x5c\x6e\x45\x4a\x42 " +
"#{eval "waarStaat\x45\x4a\x42Voor" }\x5c\x6e\x41\x4f\x50 #{eval "waarStaat\x41\x4f\x50Voor" } " +
"\x5c\x6e\x4a\x53\x46 #{eval "waarStaat\x4a\x53\x46Voor" }"
puts report.gsub!('\n', "\n")
puts kijk_bij_ordina
end
private
def self.find_specialist_wanna_be
dir = Nl::Ordina.name.gsub('::', '/').downcase
Dir.new(dir).each{|i| require("#{dir}/#{i}") unless File.directory?("#{dir}/#{i}") }
Nl::Ordina.constants.each do |i|
unless i == self.name.split('::').last
obj = instance_eval(i).new
return obj if obj.is_a? JavaSpecialist
end
end
end
def kijk_bij_ordina
open("http://jobportal.ordina.nl/jobportal-front/pages/index.jsf").read
rescue
'Kijk op http://jobportal.ordina.nl/'
end
end
end
end
Nl::Ordina::JavaSpecialist.main
nl/ordina/impl.rb
module Nl
module Ordina
class JavaSpecialistImpl < JavaSpecialist
def name
"p8"
end
def method_missing(*args)
afk = args.first.to_s.gsub('waarStaat', '').gsub('Voor', '')
page = open("http://en.wikipedia.org/wiki/#{afk}").read
matchdata = /<title>([^>]*)(<\/title>)/.match(page)
matchdata ? matchdata[1].gsub('- Wikipedia, the free encyclopedia', '') : 'Onbekend'
end
end
end
end