class Footty::Dataset
Public Instance Methods
Source
# File lib/footty/dataset.rb, line 16 def end_date @end_date ||= begin end_date = nil matches.each do |match| date = Date.strptime(match['date'], '%Y-%m-%d' ) end_date = date if end_date.nil? || date > end_date end end_date end end
Source
# File lib/footty/dataset.rb, line 11 def league_name raise ArgumentError, "method league_name must be implemented by concrete class!!" end
Source
# File lib/footty/dataset.rb, line 7 def matches raise ArgumentError, "method matches must be implemented by concrete class!!" end
Source
# File lib/footty/dataset.rb, line 44 def matches_for( date ) matches = select_matches do |match| date == Date.parse( match['date'] ) end matches end
Source
# File lib/footty/dataset.rb, line 54 def matches_within( start_date, end_date ) matches = select_matches do |match| date = Date.parse( match['date'] ) date >= start_date && date <= end_date end matches end
Source
# File lib/footty/dataset.rb, line 92 def past_matches( date: Date.today ) matches = select_matches { |match| date > Date.parse( match['date'] ) } ## note reveserve matches (chronological order/last first) ## matches.reverse matches end
Source
# File lib/footty/dataset.rb, line 63 def query( q ) ## query/check for team name match for now rx = /#{Regexp.escape(q)}/i ## use case-insensitive regex match matches = select_matches do |match| if rx.match( match['team1'] ) || rx.match( match['team2'] ) true else false end end matches end
Source
# File lib/footty/dataset.rb, line 28 def start_date @start_date ||= begin start_date = nil matches.each do |match| date = Date.strptime(match['date'], '%Y-%m-%d' ) start_date = date if start_date.nil? || date < start_date end start_date end end
Source
# File lib/footty/dataset.rb, line 40 def todays_matches( date: Date.today ) matches_for( date ); end
Source
# File lib/footty/dataset.rb, line 41 def tomorrows_matches( date: Date.today ) matches_for( date+1 ); end
Source
# File lib/footty/dataset.rb, line 80 def upcoming_matches( date: Date.today, limit: nil ) ## note: includes todays matches for now matches = select_matches { |match| date <= Date.parse( match['date'] ) } if limit matches[0, limit] ## cut-off else matches end end
Source
# File lib/footty/dataset.rb, line 52 def weeks_matches( week_start, week_end ) matches_within( week_start, week_end); end
Source
# File lib/footty/dataset.rb, line 42 def yesterdays_matches( date: Date.today ) matches_for( date-1 ); end
Private Instance Methods
Source
# File lib/footty/dataset.rb, line 101 def select_matches( &blk) selected = [] matches.each do |match| selected << match if blk.call( match ) end ## todo/fix: ## sort matches here; might not be chronologicial (by default) selected end