Created
December 22, 2011 16:11
-
-
Save russellkt/1510834 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'lib/cleared_check' | |
require 'rubygems' | |
require 'fastercsv' | |
require 'sinatra' | |
require 'json' | |
@@cleared_checks = [] | |
FasterCSV.foreach('data/cleared_checks.csv', :headers => true) do |line| | |
@@cleared_checks << ClearedCheck.new(line) | |
end | |
get '/search' do | |
content_type :json | |
@matching_checks = [] | |
if params[:amount] | |
amount = (params[:amount].to_f * 100).round | |
@matching_checks = @@cleared_checks.select{|check| check.amount == amount} | |
end | |
if params[:check_number] | |
check_number = params[:check_number] | |
if @matching_checks.size > 0 | |
@matching_checks = @matching_checks.select{|check| check.check_number == check_number} | |
elsif | |
@matching_checks = @@cleared_checks.select{|check| check.check_number == check_number } | |
end | |
end | |
@matching_checks.to_json | |
end |
This file contains hidden or 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
class ClearedCheck | |
attr_accessor :amount,:check_number,:account,:posted_on,:sequence,:image_location,:image_offset,:image_length,:image_type | |
def initialize options | |
@amount = options["amount"].gsub(",","").to_f*100.round | |
@check_number = options["check_number"] | |
@posted_on = Date.parse(options["posted_on"]) | |
end | |
def to_json(options) | |
{ :amount => @amount/100, | |
:check_number => @check_number, | |
:posted_on => @posted_on }.to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment