require "letters" class Sue MATCHERS = Hash.new("==") %w[ cats trees ].each do |key| MATCHERS[key] = ?> end %w[pomeranians goldfish ].each do |key| MATCHERS[key] = ?< end attr_reader *%i[ properties ] def initialize(properties) @properties = properties end def match?(facts) facts.select {|k,_| properties.keys.include?(k) } .all? {|k,v| properties[k].send(MATCHERS[k], v) } end end regex = /Sue (\d+): (.*)/ sues = Hash[DATA.read.scan(regex).map { |attrs| [attrs[0].to_i, Sue.new(Hash[attrs[1].split(", ") .map {|i| i.split(": ") } .map {|k,v| [k,v.to_i] }])] }] facts = Hash[<