diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index efe0522..db9ddeb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,5 +1,5 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-12-05 11:13:43 -0600 using RuboCop version 0.27.1. +# on 2014-12-07 21:50:37 -0600 using RuboCop version 0.27.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -13,7 +13,7 @@ Metrics/AbcSize: Metrics/CyclomaticComplexity: Max: 20 -# Offense count: 2 +# Offense count: 4 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 133 @@ -26,3 +26,8 @@ Metrics/MethodLength: # Offense count: 2 Metrics/PerceivedComplexity: Max: 28 + +# Offense count: 1 +# Configuration parameters: Exclude. +Style/FileName: + Enabled: false diff --git a/README.md b/README.md index 1b9de41..fe3d4c1 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,15 @@ standings = SodaXmlTeam::Standings.parse_standings(standings_document) puts standings.inspect ``` +### League Directory File Parser + +This gem includes an executable for parsing files from the [SODA League Directory](http://private.xmlteam.com/league-directory/), which is useful for handling a particular sports league. + +```bash +$ soda-league-directory ~/Downloads/xt.20140505T114154-0400.l.afa.ar.primera-leaguedir.xml +[{:import_key=>"o.afa.ar-t.113", :entity_name=>"Argentinos Juniors ", :status=>1, :entity_type=>"l.afa.ar.primera"}, {:import_key=>"o.afa.ar-t.92", :entity_name=>"Arsenal de Sarandi ", :status=>1, :entity_type=>"l.afa.ar.primera"}, ... ] +``` + ## Contributing 1. Fork it ( https://github.com/seatshare/soda_xml_team/fork ) diff --git a/bin/soda-league-directory b/bin/soda-league-directory new file mode 100755 index 0000000..eefda17 --- /dev/null +++ b/bin/soda-league-directory @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby + +require 'nokogiri' + +# Arguments +file = "#{ARGV[0]}" || nil + +if file.nil? || file == '' + puts 'Usage: soda-league-directory path-to-file.xml' + Kernel.exit(false) +end + +unless File.exist? file + puts 'File does not exist.' + Kernel.exit(false) +end + +File.open("#{ARGV[0]}", 'r') do |io| + + document = Nokogiri::XML(io) + + fail 'Invalid XML league directory.' unless document.is_a? Nokogiri::XML::Document + + output = [] + + entity_type = '' + document.css('sports-content-codes sports-content-code[code-type="league"]').each do |sportscontentcode| + entity_type = sportscontentcode['code-key'] + end + + document.css('team').each do |team| + + row = {} + + team.css('team-metadata').each do |teammeta| + row[:team_key] = teammeta['team-key'] + team.css('name').each do |namemeta| + row[:name] = namemeta['full'] + end + end + + output << row + end + + final_output = [] + # Export a create statement + output.each do |team| + next if ['', 'TBA'].include? team[:name].strip + next if team[:team_key].strip == '' + object = { + import_key: team[:team_key], + entity_name: team[:name], + status: 1, + entity_type: entity_type + } + final_output << object + end + + puts final_output.to_s + +end diff --git a/lib/soda_xml_team/version.rb b/lib/soda_xml_team/version.rb index 0840849..92dfa27 100644 --- a/lib/soda_xml_team/version.rb +++ b/lib/soda_xml_team/version.rb @@ -1,5 +1,5 @@ ## # SODA XML Team module module SodaXmlTeam - VERSION = '1.3.1' + VERSION = '1.4.0' end