module Footty

Constants

VERSION

Public Class Methods

banner() click to toggle source
main( args=ARGV ) click to toggle source
# File lib/footty.rb, line 17
def self.main( args=ARGV )
  puts banner # say hello

   league = 'en'
   year   = nil

   leagues = Dataset.leagues  ## e.g. ['world','euro',
                              ##       'de','en','at']

   ## filter args for league or year
   args = args.select do |arg|
                           if arg =~ /^\d{4}$/
                               year = arg.to_i(10)
                               false  ## eat-up
                           elsif leagues.include?( arg )
                               league = arg
                               false
                           else
                               true
                           end
                       end


  what = args[0] || 'today'
  what = what.downcase


  # Dataset.new( league: 'euro', year: 2024 )
  dataset = Dataset.new( league: league, year: year )


  ## in the future make today "configurable" as param - why? why not?
  today = Date.today

  if ['yesterday', 'y', '-1'].include?( what )
    matches = dataset.yesterdays_matches
    if matches.empty?
       puts "** No matches played yesterday.\n"
    end
  elsif ['tomorrow', 't', '+1', '1'].include?( what )
    matches = dataset.tomorrows_matches
    if matches.empty?
       puts "** No matches scheduled tomorrow.\n"
    end
  elsif ['past', 'p', 'prev'].include?( what )
    matches = dataset.past_matches
    if matches.empty?
       puts "** No matches played yet.\n"
    end
  elsif ['upcoming', 'up', 'u', 'next', 'n'].include?( what )
    matches = dataset.upcoming_matches
    if matches.empty?
       puts "** No more matches scheduled.\n"
    end
  else
     matches = dataset.todays_matches

     ## no matches today
     if matches.empty?
        puts "** No matches scheduled today.\n"

        ## note: was world cup 2018 - end date -- Date.new( 2018, 7, 11 )
        ## note: was euro 2020 (in 2021) - end date -- Date.new( 2021, 7, 11 )
        if Date.today > dataset.end_date    ## tournament is over, look back
          puts "Past matches:"
          matches = dataset.past_matches
        else  ## world cup is upcoming /in-progress,look forward
          puts "Upcoming matches:"
          matches = dataset.upcoming_matches( limit: 18 )
        end
     end
  end

  print_matches( matches )
end
print_matches( matches ) click to toggle source
root() click to toggle source
# File lib/footty/version.rb, line 9
def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end