Class: Sports::Butler::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/sports/butler/utility.rb

Class Method Summary collapse

Class Method Details

.endpointsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
82
83
84
85
# File 'lib/sports/butler/utility.rb', line 12

def endpoints
  linebreak

  Configuration::AVAILABLE_SPORT_API.each.with_index(1) do |(sport, api_names), idx|

    print white,  "#{idx}. SPORT: #{sport}\n"
    puts "==============================\n"
    puts "Endpoints for this Sport:\n\n"

    all_endpoints = "Sports::Butler::#{sport.to_s.capitalize}::ENDPOINTS".constantize
    all_endpoints.sort.each.with_index(1) do |endpoint, idx_endpoint|
      row_hash = {}
      row_hash[:available_endpoint_methods] = []
      rows_apis = []

      aliases = Sports::Butler::Base::ALIASES.map{ |key, value| key if value == endpoint }.compact
      print white, "#{idx_endpoint}. #{endpoint} [ Aliases: #{aliases.present? ? aliases.join(', ') : '-'} ]\n"

      # get all methods from all apis
      api_names.each.with_index(1) do |api_name, _idx_api_name|
        butler = Sports::Butler.new(sport: sport, api_name: api_name)

        next unless butler.available_endpoints.include?(endpoint.to_s)
        available_endpoint_methods = butler.send(endpoint).available_endpoint_methods

        row_hash[:available_endpoint_methods] += available_endpoint_methods
        row_hash[:available_endpoint_methods].uniq!

        rows_apis << api_name
      end

      rows_meths = []
      row_hash[:available_endpoint_methods].each.with_index(1) do |available_endpoint_method, idx_available|
        yes_no = []
        meth_params = []
        api_names.each.with_index(1) do |api_name, _idx_api_name|
          butler = Sports::Butler.new(sport: sport, api_name: api_name)

          next unless butler.available_endpoints.include?(endpoint.to_s)
          available_endpoint_methods = butler.send(endpoint).available_endpoint_methods

          res = available_endpoint_methods.include?(available_endpoint_method) ? 'YES' : '-'
          yes_no << res

          if available_endpoint_methods.include?(available_endpoint_method)
            params = butler.send(endpoint).method(available_endpoint_method).parameters

            res = params.present? ? params : 'none'
            meth_params << res
          else
            meth_params << '-'
          end
        end

        rows_meths << [available_endpoint_method] + yes_no
        rows_meths << [''] + meth_params
        rows_meths << :separator unless idx_available == row_hash[:available_endpoint_methods].size
      end

      table = Terminal::Table.new rows: rows_meths
      table.title = "Endpoint #{endpoint} [#{sport}]"
      table.headings = ['Method'] + rows_apis

      print magenta, table

      linebreak
      linebreak
    end
    linebreak
  end
  linebreak

  true
end

.linebreakObject

output



88
89
90
# File 'lib/sports/butler/utility.rb', line 88

def linebreak
  puts "\n"
end