From: Matthew Rudy Jacobs Date: 2008-06-08T03:43:55+09:00 Subject: Re: Price Ranges (#164) I assumed that input had to be taken in the way outlined in the challenge. So most of my code is about parsing that to create the required ranges. ========================= class String def better_to_f str = match(/\D*([0-9,.]+)/)[1] str.gsub!(',','_') str.to_f end end $vendors = <<-STRING Company A: $1,000 - $3,000 Company B: $6,000 - $10,000 Company C: $500 - $2,500 STRING vendor_regexp = /(\w.*\w):\s*\$([0-9,.]+) - \$([0-9,.]+)/ $shopper = <<-STRING Low: $3,500 High: $7,000 STRING require 'yaml' parsed = YAML.parse($shopper) low = parsed['Low'] && parsed['Low'].value.better_to_f high = parsed['High'] && parsed['High'].value.better_to_f vendors = $vendors.scan(vendor_regexp) result = [] vendors.each do |name, min, max| min = min.better_to_f max = max.better_to_f if low && low > max next elsif high && high < min next else result << name end end -- Posted via http://www.ruby-forum.com/.