Module: Fbpp
- Defined in:
- lib/fbtxt-pp/tool-fbpp.rb
Overview
or use (alternate) Fbtxtpp - why? why not?
Class Method Summary collapse
Class Method Details
.main(args = ARGV) ⇒ Object
6 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fbtxt-pp/tool-fbpp.rb', line 6 def self.main( args=ARGV ) opts = { full: false, ## incl. line-ups, penalties, referees, etc. min: false, ## (minimal) no dates, no venues, no goals, no half-time score, etc. season: nil, ## use/rename to cache_dir - why? why not? convert_dir: '/sports/cache.api.fifa', } parser = OptionParser.new do |parser| parser. = "Usage: #{$PROGRAM_NAME} [options] NAME" parser.on( "--full", "turn on full mode incl. line-up, pens, & more (default: #{opts[:full]})" ) do |full| opts[:full] = true end parser.on( "--min", "--minimal", "turn on min(imal) mode (default: #{opts[:min]})" ) do |min| opts[:min] = true end parser.on( "--season=SEASON", "season (default: #{opts[:season]||'none'})" ) do |season| opts[:season] = season end end parser.parse!( args ) puts "OPTS:" pp opts puts "ARGV:" pp args if args.size == 0 puts " NAME argument required; use:" pp CONFIGS.keys exit 1 end ## ## note - all args other than first ignored for now; issue warn - why? why not? key = args[0].downcase.to_sym config = CONFIGS[ key ] puts "CONFIG:" pp config if config.nil? ## auto-fill with defaults!! config = { slug: key, name: "#{key}", seasons: [], opts: { country: false, stadium: false, city: false, timezone: false, }, opts_full: { country: false, }, } end slug = config[:slug] ## change to source - why? why not? seasons = opts[:season] ? [opts[:season]] : config[:seasons] ## outdir = "../../openfootball/clubworldcup" ## outdir = "." outdir = "./tmp" seasons.each do |season| season = Season(season) name = config[:name].is_a?(Proc) ? config[:name].call( season ) : config[:name] page = String.new page << "= #{name} #{season}\n" page << "\n" buf = if opts[:full] pp_matches_full( slug: slug, season: season, indir: opts[:convert_dir], opts: FormatOpts.build_full( **config[:opts_full] )) elsif opts[:min] pp_matches_min( slug: slug, season: season, indir: opts[:convert_dir], opts: FormatOpts.build_min( **config[:opts] )) else pp_matches( slug: slug, season: season, indir: opts[:convert_dir], opts: FormatOpts.build(**config[:opts] )) end page << buf puts page outpath = if opts[:full] "#{outdir}/more/#{season.to_path}_#{slug}-full.txt" elsif opts[:min] "#{outdir}/min/#{season.to_path}_#{slug}.txt" else "#{outdir}/more/#{season.to_path}_#{slug}.txt" end write_text( outpath, page ) ## puts " opts:" ## pp opts puts " written to >#{outpath}<" end puts "bye" end |