Module: Footty

Defined in:
lib/footty.rb,
lib/footty/client.rb,
lib/footty/version.rb

Defined Under Namespace

Classes: Client

Constant Summary collapse

VERSION =
'2024.5.10'

Class Method Summary collapse

Class Method Details



5
6
7
# File 'lib/footty/version.rb', line 5

def self.banner
  "footty/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
end

.clientObject



23
24
25
26
# File 'lib/footty.rb', line 23

def self.client
  ## note: hard code tournament / league for now
  @client ||= Client.new( league: 'euro', year: 2024 )    ## use "singelton" / shared client
end

.mainObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/footty.rb', line 30

def self.main
  puts banner # say hello

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

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

  if ['yesterday', 'y', '-1'].include?( what )
    matches = client.yesterdays_matches
    if matches.empty?
       puts "** No matches played yesterday.\n"
    end
  elsif ['tomorrow', 't', '+1', '1'].include?( what )
    matches = client.tomorrows_matches
    if matches.empty?
       puts "** No matches scheduled tomorrow.\n"
    end
  elsif ['past', 'p', 'prev'].include?( what )
    matches = client.past_matches
    if matches.empty?
       puts "** No matches played yet.\n"
    end
  elsif ['upcoming', 'up', 'u', 'next', 'n'].include?( what )
    matches = client.upcoming_matches
    if matches.empty?
       puts "** No more matches scheduled.\n"
    end
  else
     matches = client.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 > Date.new( 2024, 7, 14 )     ## tournament is over, look back
          puts "Past matches:"
          matches = client.past_matches
        else  ## world cup is upcoming /in-progress,look forward
          puts "Upcoming matches:"
          matches = client.upcoming_matches
        end
     end
  end



  print_matches( matches )
end


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/footty.rb', line 85

def self.print_matches( matches )
  ## print games

  today = Date.today

  matches.each do |match|
    print "   %5s" % "\##{match['num']} "

    date = Date.parse( match['date'] )
    print "#{date.strftime('%a %b/%d')} "      ## e.g. Thu Jun/14
    if date > today
       diff = (date - today).to_i
       print "%10s" % "(in #{diff}d) "
    end

    print "%22s" % "#{match['team1']['name']} (#{match['team1']['code']})"

    ## todo/fix: add support for knockout scores
    ##                 with score1et/score1p  (extra time and penalty)
    if match['score1'] && match['score2']
      print " #{match['score1']}-#{match['score2']} "
      print "(#{match['score1i']}-#{match['score2i']}) "
    else
      print "    vs    "
    end

    print "%-22s" % "#{match['team2']['name']} (#{match['team2']['code']})"

    if match['group']
      print " #{match['group']} /"    ## group phase/stage
    end

    print " #{match['round']} "    ## knock out (k.o.) phase/stage

    if match['stadium']
      print " @ #{match['stadium']['name']}, #{match['city']}"
    end

    print "\n"


    if match['goals1'] && match['goals2']
      print "                     ["
      match['goals1'].each_with_index do |goal,i|
        print " "    if i > 0
        print "#{goal['name']}"
        print " #{goal['minute']}"
        print "+#{goal['offset']}"   if goal['offset']
        print "'"
        print " (o.g.)"    if goal['owngoal']
        print " (pen.)"    if goal['penalty']
      end
      match['goals2'].each_with_index do |goal,i|
        if i == 0
          print "; "
        else
         print " "
        end
        print "#{goal['name']}"
        print " #{goal['minute']}"
        print "+#{goal['offset']}"  if goal['offset']
        print "'"
        print " (o.g.)"  if goal['owngoal']
        print " (pen.)"  if goal['penalty']
      end
      print "]\n"
    end


  end
end

.rootObject



9
10
11
# File 'lib/footty/version.rb', line 9

def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end