Class: DataValidation::Comparison::RankingTableProPrComparison
- Inherits:
-
Object
- Object
- DataValidation::Comparison::RankingTableProPrComparison
- Defined in:
- lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb
Instance Attribute Summary collapse
-
#web_url ⇒ Object
readonly
Returns the value of attribute web_url.
Instance Method Summary collapse
- #api_path ⇒ Object
- #compare ⇒ Object
- #field_array ⇒ Object
-
#initialize(web_url) ⇒ RankingTableProPrComparison
constructor
A new instance of RankingTableProPrComparison.
- #logger ⇒ Object
Constructor Details
#initialize(web_url) ⇒ RankingTableProPrComparison
Returns a new instance of RankingTableProPrComparison.
7 8 9 |
# File 'lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb', line 7 def initialize(web_url) @web_url = web_url end |
Instance Attribute Details
#web_url ⇒ Object (readonly)
Returns the value of attribute web_url.
5 6 7 |
# File 'lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb', line 5 def web_url @web_url end |
Instance Method Details
#api_path ⇒ Object
11 12 13 |
# File 'lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb', line 11 def api_path '/rest/LaxPower/rankingTableProPR' end |
#compare ⇒ Object
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 |
# File 'lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb', line 19 def compare div_id = web_url.match(/mll/) ? '12' : '11' season = 2017 is_old_season = false web_data = DataValidation::DataAccess.get_pro_pr_table web_url api_data = (DataValidation::DataAccess.get_pr_for_pro season, 'PRO', div_id) if api_data.nil? season = 2016 api_data = DataValidation::DataAccess.get_pr_for_pro season, 'PRO', div_id is_old_season = true end @logger_name = "log/#{season}/pro/pr/#{season}_pro_#{div_id}.log" if is_old_season puts 'This PR ranking is still for 2016' end if web_data.size != api_data.size logger.error 'team size is incorrect' else web_data.each_with_index do |web_record, index| api_record = api_data[index] field_array.each_with_index do |field_name, i| api_record_item = api_record[field_name] web_record_item = web_record[i] if (api_record_item.is_a?(String) && !api_record_item.include?(web_record_item.strip)) || ((api_record_item.is_a?(Float) && api_record_item != web_record_item.to_f)) || ((api_record_item.is_a?(Integer) && api_record_item != web_record_item.to_i)) logger.error "team #{index + 1}'s #{field_name}: #{api_record_item} -- #{web_record_item}" end end end end end |
#field_array ⇒ Object
15 16 17 |
# File 'lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb', line 15 def field_array ['rank', 'teamName', 'powerRating', %w|record wins|, %w|record losses|] end |
#logger ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb', line 58 def logger @logger ||= begin tokens = @logger_name.split('/') 1.upto(tokens.size - 1) do |n| dir = tokens[0...n].join('/') Dir.mkdir(dir) unless Dir.exist?(dir) end logger = Logger.new(File.new(@logger_name, 'w')) logger.info(web_url) logger end end |