Class: DataValidation::Comparison::RankingTableMwPollComparison

Inherits:
ComparisonBase
  • Object
show all
Defined in:
lib/data_validation/comparison/ranking_table_mw_poll_comparison.rb,
lib/data_validation/comparison/conference_ranking_table_comparison.rb

Instance Attribute Summary

Attributes inherited from ComparisonBase

#category, #division_id, #logger_name, #season, #web_url

Instance Method Summary collapse

Methods inherited from ComparisonBase

#compare_conf_standings, #initialize

Constructor Details

This class inherits a constructor from DataValidation::Comparison::ComparisonBase

Instance Method Details

#api_pathObject



7
8
9
# File 'lib/data_validation/comparison/ranking_table_mw_poll_comparison.rb', line 7

def api_path
  '/rest/LaxPower/rankingTableMWpoll'
end

#compareObject



7
8
9
10
11
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
# File 'lib/data_validation/comparison/conference_ranking_table_comparison.rb', line 7

def compare

  if api_path.nil?
    raise 'Please define api_path'
  end

  data_access = DataValidation::DataAccess.new(web_url, DataValidation.api_request_host + api_path, determine_request_body_and_logger_name)

  puts 'requesting web page...'
  web_data = data_access.get_main_table_data
  puts 'requesting mobile api data: ' + DataValidation.api_request_host + api_path
  api_data = data_access.get_response_from_mobile_api

  if web_data.length != api_data['results']['results']['total']
    logger.error "The record size between web page and api data is not the same: #{web_data.length} -- #{api_data['results']['results']['total']}"
    return
  end

  web_data.each_with_index do |item, index|
    team = api_data['results']['results']['teams'][index]

    field_array.each_with_index do |filed_name, index|
      if filed_name.is_a? String
        team_value = team[filed_name]
      elsif filed_name.is_a? Array
        team_value = team[filed_name[0]][filed_name[1]]
      else
        next
      end

      unless (team_value.is_a?(String) && team_value.include?(item[index])) ||
        (team_value.is_a?(Float) && team_value == item[index].to_f) ||
        (team_value.is_a?(Integer) && team_value == item[index].to_i)

        logger.error "team #{item[0]}'s #{filed_name} is not correct: #{item[index]} -- #{team_value}"
      end
    end

  end
end

#empty_fieldObject



15
16
17
# File 'lib/data_validation/comparison/ranking_table_mw_poll_comparison.rb', line 15

def empty_field
  'pollFirst'
end

#field_arrayObject



11
12
13
# File 'lib/data_validation/comparison/ranking_table_mw_poll_comparison.rb', line 11

def field_array
  ['rank', 'teamName', %w|record wins|, %w|record losses|, %w|record ties|, 'pollPoint', 'pollFirst']
end