Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
League parser
Browse files Browse the repository at this point in the history
Adds a utility executable for parsing files from the [SODA League Directory](http://private.xmlteam.com/league-directory/), which is useful for handling a particular sports league.
  • Loading branch information
stephenyeargin committed Dec 8, 2014
1 parent 4db3f8e commit 8fc5448
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
9 changes: 7 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,7 +13,7 @@ Metrics/AbcSize:
Metrics/CyclomaticComplexity:
Max: 20

# Offense count: 2
# Offense count: 4
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 133
Expand All @@ -26,3 +26,8 @@ Metrics/MethodLength:
# Offense count: 2
Metrics/PerceivedComplexity:
Max: 28

# Offense count: 1
# Configuration parameters: Exclude.
Style/FileName:
Enabled: false
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
61 changes: 61 additions & 0 deletions bin/soda-league-directory
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/soda_xml_team/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
# SODA XML Team module
module SodaXmlTeam
VERSION = '1.3.1'
VERSION = '1.4.0'
end

0 comments on commit 8fc5448

Please sign in to comment.