football-cat 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f049230d455d5f193ef47130fc8fceb5c24f170
4
- data.tar.gz: b03a2d436aec95aa8bac7f02f36b2e35aee4336b
3
+ metadata.gz: f5ec4bf16056fff1c0b767ad696d563852a5e107
4
+ data.tar.gz: 809bf72089bef2491ddefea64d247e01b468aa2c
5
5
  SHA512:
6
- metadata.gz: c96ad2a9b2516d1c44ea872ac8f43ff7135a7591009d7e4aebe7c1077a6f367551ef893d11b6f01f4dea9fefe23b8ca44db4b2010b297c333d3891f73a66c9ce
7
- data.tar.gz: b99f5b5e26dcdf52c00aebc345166e01f85ea256976a0f9d0bc7488db2a4d8c62fba5d0d33ed85e00bf9173e21c0e4f556a175ddb6f3aa7c3303d80500f3b610
6
+ metadata.gz: '08b0fb02547bea1de411aa9efb0d55c28d6aef6d980b427703cbb99d7ab92a1f316bd0a228bc10bc8c9abdd210f6936cd816ddaf94cd16bcd00de0ca9acc646e'
7
+ data.tar.gz: 3fdd83eb41a43efef8b722a617f56f9074a3f53d8410c8b5d481335c44f0263fecdcb9fa27e4071ef1984964eb757869a2ef256ac8ca5e29aeb26d6a25bf7c43
@@ -4,6 +4,7 @@ README.md
4
4
  Rakefile
5
5
  bin/football-cat
6
6
  lib/football-cat.rb
7
+ lib/football-cat/tool.rb
7
8
  lib/football-cat/version.rb
8
9
  test/helper.rb
9
10
  test/test_version.rb
@@ -0,0 +1,115 @@
1
+
2
+ module FootballCat
3
+ class Tool
4
+
5
+
6
+ def initialize
7
+ end
8
+
9
+
10
+ def run( args )
11
+
12
+ options = {}
13
+ optparser = OptionParser.new do |parser|
14
+ parser.banner = "Usage: football-cat [options] OUTPATH INPATHS..."
15
+ end
16
+ optparser.parse!( args )
17
+
18
+ if args.empty?
19
+ puts "!! ERROR - football.csv name/path expected (e.g. league.csv)"
20
+ puts optparser.help
21
+ exit 1
22
+ end
23
+
24
+ outpath = args.shift
25
+ puts "outpath: >#{outpath}<"
26
+ puts "args:"
27
+ p args
28
+
29
+ headers = nil
30
+
31
+ args.each do |arg|
32
+ inpath = File.expand_path( arg )
33
+ puts "reading #{inpath}..."
34
+
35
+ if File.directory?( inpath )
36
+ pack = SportDb::DirPackage.new( inpath )
37
+ pack.each_csv do |entry|
38
+ puts " #{entry.name}"
39
+
40
+ basename = File.basename( entry.name, File.extname( entry.name ) ) ## get basename WITHOUT extension
41
+
42
+ ## note: upcase for now and remove dots e.g.
43
+ ## es.1 => ES1
44
+ ## de.cup => DECUP - why? why not?
45
+ league_key = basename.upcase.gsub( '.', '' )
46
+
47
+ ## todo/fix: check if season_key is proper season - e.g. matches pattern !!!!
48
+ season_q = File.basename( File.dirname( entry.name ))
49
+ season = Season.parse( season_q ) ## normalize season
50
+ season_key = season.key
51
+
52
+ puts " league: #{league_key}, season: #{season_key}"
53
+
54
+ txt = entry.read
55
+ ## matches = SportDb::CsvMatchParser.parse( txt )
56
+ rows = CsvHash.parse( txt )
57
+ puts " addinging #{rows.size} match(es)..."
58
+ # rows = rows.map do |row|
59
+ # { 'League' => league_key,
60
+ # 'Season' => season_key }.merge( row )
61
+ # end
62
+ # pp rows[0..2]
63
+
64
+ if headers.nil?
65
+ ## first time - create file with headers
66
+ headers = ['League', 'Season'] + rows[0].keys
67
+ puts "headers:"
68
+ pp headers
69
+
70
+ FileUtils.mkdir_p( File.dirname( outpath )) ## make sure path exists
71
+ File.open( outpath, 'w:utf-8' ) do |f|
72
+ f.write( headers.join(',') )
73
+ f.write( "\n" )
74
+ end
75
+ end
76
+
77
+ File.open( outpath, 'a:utf-8' ) do |f|
78
+ rows.each do |row|
79
+ f.write( csv_encode( [ league_key, season_key ] + row.values ))
80
+ f.write( "\n")
81
+ end
82
+ end
83
+ end
84
+ else ## assume "free-standing" single datatfile
85
+ puts "!! WARN - skipping datafile >#{inpath}< - sorry - for now only directories / packages work"
86
+ end
87
+ end
88
+
89
+
90
+ puts "Done."
91
+ end # method run
92
+
93
+ ##########
94
+ # helpers
95
+ def csv_encode( values )
96
+ ## quote values that incl. a comma
97
+ values.map do |value|
98
+ if value.index(',')
99
+ puts "** rec with field with comma:"
100
+ pp values
101
+ %Q{"#{value}"}
102
+ else
103
+ value
104
+ end
105
+ end.join( ',' )
106
+ end
107
+
108
+
109
+ end # class Tool
110
+
111
+
112
+ def self.main( args=ARGV )
113
+ Tool.new.run( args )
114
+ end
115
+ end # module FootballCat
@@ -4,7 +4,7 @@ module FootballCat
4
4
 
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 1
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football-cat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -75,6 +75,7 @@ files:
75
75
  - Rakefile
76
76
  - bin/football-cat
77
77
  - lib/football-cat.rb
78
+ - lib/football-cat/tool.rb
78
79
  - lib/football-cat/version.rb
79
80
  - test/helper.rb
80
81
  - test/test_version.rb