Class: SportSearch::LeagueSearch
- Defined in:
- lib/sportdb/search/sport.rb
Instance Attribute Summary
Attributes inherited from Search
Instance Method Summary collapse
- #find(q) ⇒ Object
-
#find!(q) ⇒ Object
more deriv support functions / helpers.
-
#match(q, country: nil) ⇒ Object
all-in-one query (name or code).
-
#match_by(name: nil, code: nil, country: nil) ⇒ Object
core required delegates - use delegate generator - why? why not?.
Methods inherited from Search
Constructor Details
This class inherits a constructor from SportSearch::Search
Instance Method Details
#find(q) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sportdb/search/sport.rb', line 60 def find( q ) league = nil recs = match( q ) # pp m if recs.empty? ## fall through/do nothing elsif recs.size > 1 puts "** !!! ERROR - ambigious league query; too many leagues (#{recs.size}) found:" pp recs exit 1 else league = recs[0] end league end |
#find!(q) ⇒ Object
more deriv support functions / helpers
51 52 53 54 55 56 57 58 |
# File 'lib/sportdb/search/sport.rb', line 51 def find!( q ) league = find( q ) if league.nil? puts "** !!! ERROR - no league match found for >#{q}<, add to leagues table; sorry" exit 1 end league end |
#match(q, country: nil) ⇒ Object
all-in-one query (name or code)
44 45 46 |
# File 'lib/sportdb/search/sport.rb', line 44 def match( q, country: nil ) @service.match_by_name_or_code( q, country: country ) end |
#match_by(name: nil, code: nil, country: nil) ⇒ Object
core required delegates - use delegate generator - why? why not?
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sportdb/search/sport.rb', line 29 def match_by( name: nil, code: nil, country: nil ) ## todo/fix upstream - remove "generic" match_by() - why? why not? ### if code && name.nil? @service.match_by_code( code, country: country ) elsif name && code.nil? @service.match_by_name( name, country: country ) else raise ArgumentError, "LeagueSearch#match_by - one (and only one arg) required - code: or name:" end ## @service.match_by( name: name, ## country: country ) end |