Class: Footty::Dataset
- Inherits:
-
Object
- Object
- Footty::Dataset
- Defined in:
- lib/footty/dataset/dataset.rb
Overview
note - assume “upstream” date is always date object or nil (NOT string)!!!
Direct Known Subclasses
Instance Method Summary collapse
- #_select_matches(&blk) ⇒ Object
- #end_date ⇒ Object
- #league_name ⇒ Object
- #matches ⇒ Object
- #past_matches(date: Date.today) ⇒ Object
- #query(q) ⇒ Object
- #start_date ⇒ Object
- #todays_matches(date: Date.today) ⇒ Object
- #tomorrows_matches(date: Date.today) ⇒ Object
- #upcoming_matches(date: Date.today, limit: nil) ⇒ Object
- #weeks_matches(start_week, end_week) ⇒ Object
- #yesterdays_matches(date: Date.today) ⇒ Object
Instance Method Details
#_select_matches(&blk) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/footty/dataset/dataset.rb', line 91 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 |
#end_date ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/footty/dataset/dataset.rb', line 19 def end_date @end_date ||= begin end_date = nil matches.each do |match| end_date = match['date'] if end_date.nil? || match['date'] > end_date end end_date end end |
#league_name ⇒ Object
13 14 15 |
# File 'lib/footty/dataset/dataset.rb', line 13 def league_name raise ArgumentError, "method league_name must be implemented by concrete class!!" end |
#matches ⇒ Object
9 10 11 |
# File 'lib/footty/dataset/dataset.rb', line 9 def matches raise ArgumentError, "method matches must be implemented by concrete class!!" end |
#past_matches(date: Date.today) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/footty/dataset/dataset.rb', line 65 def past_matches( date: Date.today ) matches = _select_matches { |match| date > match['date'] } ## note reveserve matches (chronological order/last first) ## matches.reverse matches end |
#query(q) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/footty/dataset/dataset.rb', line 74 def query( q ) ## query/check for team name match for now rx = /#{Regexp.escape(q)}/i ## use case-insensitive regex match _select_matches do |match| if rx.match( match['team1'] ) || rx.match( match['team2'] ) true else false end end end |
#start_date ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/footty/dataset/dataset.rb', line 29 def start_date @start_date ||= begin start_date = nil matches.each do |match| start_date = date = match['date'] if start_date.nil? || date = match['date'] < start_date end start_date end end |
#todays_matches(date: Date.today) ⇒ Object
40 |
# File 'lib/footty/dataset/dataset.rb', line 40 def todays_matches( date: Date.today ) _select_matches { |match| date == match['date'] }; end |
#tomorrows_matches(date: Date.today) ⇒ Object
41 |
# File 'lib/footty/dataset/dataset.rb', line 41 def tomorrows_matches( date: Date.today ) _select_matches { |match| date+1 == match['date'] }; end |
#upcoming_matches(date: Date.today, limit: nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/footty/dataset/dataset.rb', line 52 def upcoming_matches( date: Date.today, limit: nil ) ## note: includes todays matches for now matches = _select_matches { |match| date <= match['date'] } if limit matches[0, limit] ## cut-off else matches end end |
#weeks_matches(start_week, end_week) ⇒ Object
45 46 47 48 49 |
# File 'lib/footty/dataset/dataset.rb', line 45 def weeks_matches( start_week, end_week ) _select_matches do |match| match['date'] >= start_week && match['date'] <= end_week end end |
#yesterdays_matches(date: Date.today) ⇒ Object
42 |
# File 'lib/footty/dataset/dataset.rb', line 42 def yesterdays_matches( date: Date.today ) _select_matches { |match| date-1 == match['date'] }; end |