class PetSearch
Attributes
api_key[RW]
api_secret[RW]
barnyard[RW]
bird[RW]
cat[RW]
dog[RW]
horse[RW]
pig[RW]
reptile[RW]
smallfurry[RW]
Public Class Methods
init_options(*args)
click to toggle source
# File lib/petsearch.rb, line 23 def self.init_options(*args) @@options = Hash.new begin @@options[:breeds] = args.grep(/[Bb]reeds/).first.downcase.match(/(?<=breeds=).*/)[0].split(',') if args.grep(/[Bb]reeds/).first @@options[:animal] = args.grep(/[Dd]og|[Cc]at|[Bb]ird|[Rr]eptile|[Hh]orse|[Pp]ig|[Bb]arnyard|[Ss]mallfurry/).first @@options[:age] = args.grep(/[Bb]aby|[Yy]oung|[Aa]dult|[Ss]enior/).first @@options[:location] = args.grep(/\d{5}/).first.strip @@options[:sex] = args.grep(/[Ss]ex/).first.downcase.match(/(?<=sex=).*/)[0].upcase if args.grep(/[Ss]ex/).first if (args.grep(/[Ss]m|[Mm]dm|[Ll]rg|[Xx]l/).length == 2) @@options[:size] = args.grep(/[Ss]m|[Mm]dm|[Ll]rg|[Xx]l/)[1].downcase elsif (args.grep(/[Ss]m|[Mm]dm|[Ll]rg|[Xx]l/).length == 1) @@options[:size] = args.grep(/[Ss]m|[Mm]dm|[Ll]rg|[Xx]l/).first.downcase else @@options[:size]=nil end case (@@options[:size]) when 'sm' @@options[:size] = 'S' when 'mdm' @@options[:size] = 'M' when 'lrg' @@options[:size] = 'L' when 'xl' @@options[:size] = 'XL' end @@options[:random] = args.grep(/[Tt]rue|[Ff]alse/).first @@options[:offset] = args.grep(/[Oo]ff/).first.downcase.match(/(?<=off).*/)[0] if args.grep(/[Oo]ff/).first @@options[:count] = args.grep(/[Cc]t/).first.downcase.match(/(?<=ct).*/)[0] if args.grep(/[Cc]t/).first rescue NoMethodError puts "You have an error in your parameters" end end
new()
click to toggle source
# File lib/petsearch.rb, line 12 def initialize @dog = {:name => 'dog', :breeds => []} @cat = {:name => 'cat', :breeds => []} @bird = {:name => 'bird', :breeds => []} @reptile = {:name => 'reptile', :breeds => []} @horse = {:name => 'horse', :breeds => []} @pig = {:name => 'horse', :breeds => []} @barnyard = {:name => 'horse', :breeds => []} @smallfurry = {:name => 'smallfurry', :breeds => []} end
options()
click to toggle source
# File lib/petsearch.rb, line 58 def self.options @@options end
search()
click to toggle source
# File lib/petsearch.rb, line 62 def self.search PetClient.search_listings(@@options) end