football_cli 0.0.5 → 0.0.6

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: 96b922552deebad259c1b6793fde2462d7cc3312
4
- data.tar.gz: 2f96cb95a21c007c6a7543a0b8968a60ba016f43
3
+ metadata.gz: 1df441d44406edc4be111c1116102489aed819c1
4
+ data.tar.gz: de99649c3dcadb29610f06dd83db866fda0e56da
5
5
  SHA512:
6
- metadata.gz: 5d008a3907dfeeeff4cc6d26577b7a4446b9163dc15bc1237fcd3f459051c3c94a6f7d56a0d15031c03f97367c65a219bb501416d01bf98be125c9e333fbe7eb
7
- data.tar.gz: 09b2e569be8e5c2938ee794efe8cad5b67f1c942d878b1624c47ae371cb947371937b6a4a49802a6cabfa3a0942134600a0b4362eb73d618d3e47125f99ed19b
6
+ metadata.gz: 036089059d5fc065ad442940e669846fa9c7cadce35b88e396803a48ed490911bd2cae729445f3c4d98ae30fa962f47fe877ee7605a74ad333ba054668b2db43
7
+ data.tar.gz: 9fc52868aa7c04995e55b05015f60bbe7af84312f0ced1de427345d2fc3a31b571620210a9c3c1f82f88a7d302c9d1d1a2ecaa992c7930517a4383440882a4d2
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- football_cli (0.0.5)
4
+ football_cli (0.0.6)
5
5
  football_ruby
6
- gli (= 2.16.0)
7
6
  rainbow
7
+ thor
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -35,7 +35,6 @@ GEM
35
35
  ffi (1.9.18)
36
36
  football_ruby (0.1.2)
37
37
  gherkin (4.1.3)
38
- gli (2.16.0)
39
38
  multi_json (1.12.1)
40
39
  multi_test (0.1.2)
41
40
  rainbow (2.2.2)
data/bin/football_cli CHANGED
@@ -1,63 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'gli'
3
2
  require 'football_cli'
4
3
 
5
- include GLI::App
6
-
7
- program_desc 'Football scores for geeks.'
8
-
9
- version FootballCli::VERSION
10
-
11
- subcommand_option_handling :normal
12
- arguments :strict
13
-
14
- desc 'Show leagues, team players, fixtures and more'
15
- command :show do |c|
16
- c.desc 'Specify league code'
17
- c.flag [:l, :league]
18
-
19
- c.desc 'Specify match day'
20
- c.flag [:md, :match_day]
21
-
22
- c.desc 'Specify team code'
23
- c.flag [:t, :team]
24
-
25
- c.desc 'Specify format'
26
- c.flag [:ft, :format]
27
-
28
- c.desc 'Specify file name to save output'
29
- c.flag [:fl, :file]
30
-
31
- c.switch [:p, :players]
32
- c.switch [:fs, :fixtures]
33
-
34
- c.action do |global_options, options, args|
35
- @handler.run
36
- end
37
- end
38
-
39
- desc 'Display live scores'
40
- command :live do |c|
41
- c.action do |global_options,options,args|
42
- @handler.run
43
- end
44
- end
45
-
46
- pre do |global,command,options,args|
47
- @handler = FootballCli::Handler.new(command.name, options)
48
- end
49
-
50
- post do |global,command,options,args|
51
- # Post logic here
52
- # Use skips_post before a command to skip this
53
- # block on that command only
54
- end
55
-
56
- on_error do |exception|
57
- # Error logic here
58
- # return false to skip default error handling
59
- puts "----- backtrace: #{exception.backtrace}"
60
- true
61
- end
62
-
63
- exit run(ARGV)
4
+ FootballCli::CLI.start( ARGV )
data/football_cli.gemspec CHANGED
@@ -22,10 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.executables << 'football_cli'
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency('football_ruby')
26
- spec.add_dependency('rainbow')
27
- spec.add_development_dependency('rake')
28
- spec.add_development_dependency('aruba')
29
- spec.add_development_dependency('terminal-table')
30
- spec.add_runtime_dependency('gli','2.16.0')
25
+ spec.add_dependency 'thor'
26
+ spec.add_dependency 'football_ruby'
27
+ spec.add_dependency 'rainbow'
28
+
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'aruba'
31
+ spec.add_development_dependency 'terminal-table'
31
32
  end
data/lib/football_cli.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'football_cli/handler'
2
1
  require 'football_cli/version'
2
+ require 'football_cli/cli'
@@ -0,0 +1,32 @@
1
+ require 'thor'
2
+ require_relative 'handler'
3
+
4
+ module FootballCli
5
+ class CLI < Thor
6
+ desc 'show', 'sample description'
7
+
8
+ option :league
9
+ option :match_day, type: :numeric
10
+ option :format
11
+ option :file
12
+
13
+ option :team
14
+ class_option :players, type: :boolean
15
+ class_option :fixtures, type: :boolean
16
+
17
+ def show
18
+ handler.run
19
+ end
20
+
21
+ desc 'live', 'display live scores'
22
+ def live
23
+ handler.live_scores
24
+ end
25
+
26
+ private
27
+
28
+ def handler
29
+ FootballCli::Handler.new(options)
30
+ end
31
+ end
32
+ end
@@ -1,7 +1,7 @@
1
1
  module FootballCli
2
2
  module Format
3
3
  class Base
4
- attr_reader :title, :response, :columns, :rows, :file_name
4
+ attr_reader :title, :response, :columns, :rows
5
5
 
6
6
  def initialize(opts={})
7
7
  @response = opts[:response]
@@ -18,33 +18,17 @@ module FootballCli
18
18
  end
19
19
 
20
20
  def output
21
- raise NotImplementedError, 'must implement output() method in subclass'
22
- end
23
-
24
- def write_to_file(output)
25
- File.write(file_name, output) if file_name
21
+ if @file_name
22
+ File.write(@file_name, generate)
23
+ else
24
+ puts generate
25
+ end
26
26
  end
27
27
 
28
28
  def goal_columns
29
29
  %i(goalsHomeTeam goalsAwayTeam).freeze
30
30
  end
31
31
 
32
- def pretty_table(data, column)
33
- if qualification
34
- color = case data[:position]
35
- when qualification[:cl] then :green
36
- when qualification[:el] then :yellow
37
- when qualification[:rl] then :red
38
- else
39
- :aqua
40
- end
41
-
42
- data[column].to_s.color(color)
43
- else
44
- data[column]
45
- end
46
- end
47
-
48
32
  def qualification
49
33
  Hash[@qualification.collect {|k, v| [ k, v.each_cons(2).map {|from, to| from..to }.max ] }] if @qualification
50
34
  end
@@ -19,12 +19,6 @@ module FootballCli
19
19
  end
20
20
  end
21
21
  end
22
-
23
- def output
24
- puts generate
25
-
26
- write_to_file(generate)
27
- end
28
22
  end
29
23
  end
30
24
  end
@@ -19,12 +19,6 @@ module FootballCli
19
19
 
20
20
  @generate ||= JSON.pretty_generate(rows)
21
21
  end
22
-
23
- def output
24
- puts generate
25
-
26
- write_to_file(generate)
27
- end
28
22
  end
29
23
  end
30
24
  end
@@ -6,28 +6,34 @@ module FootballCli
6
6
  class Table < Base
7
7
  def generate
8
8
  response.each do |data|
9
- rows.push(
10
- columns.collect {|c|
11
- if goal_columns.include?(c) && data[:result] # when requesting team's fixtures
12
- data[:result][c]
13
- else
14
- pretty_table(data, c)
15
- end
16
- }
17
- )
9
+ rows.push(columns.collect {|column| pretty_table(data, column) })
18
10
  end
19
11
 
20
- Terminal::Table.new do |t|
12
+ @generate ||= Terminal::Table.new do |t|
21
13
  t.title = title
22
14
  t.headings = columns.map(&:capitalize)
23
15
  t.rows = rows
24
16
  end
25
17
  end
26
18
 
27
- def output
28
- puts generate
19
+ def pretty_table(data, column)
20
+ if qualification
21
+ data[column].to_s.color(get_color(data[:position]))
22
+ elsif goal_columns.include?(column) && data[:result]
23
+ data[:result][column]
24
+ else
25
+ data[column]
26
+ end
27
+ end
29
28
 
30
- write_to_file(generate)
29
+ def get_color(data)
30
+ case data
31
+ when qualification[:cl] then :green
32
+ when qualification[:el] then :yellow
33
+ when qualification[:rl] then :red
34
+ else
35
+ :aqua
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -9,43 +9,32 @@ module FootballCli
9
9
  class Handler
10
10
  include FootballCli::Mapper
11
11
 
12
- def initialize(command, options={})
13
- @command = command
12
+ def initialize(options={})
14
13
  @league = options[:league]
15
14
  @match_day = options[:match_day]
16
15
  @players = options[:players]
17
16
  @fixtures = options[:fixtures]
18
17
  @team = options[:team]
19
- @format = options[:format] || 'table'
20
18
  @file = options[:file]
19
+ @format = options.fetch(:format, 'table')
21
20
  end
22
21
 
23
22
  def run
24
- case command
25
- when :live
26
- live_scores
27
- when :show
28
- case
29
- when league, match_day
30
- league_table
31
- when team && players, fixtures
32
- if players
33
- team_players
34
- elsif fixtures
35
- team_fixtures
36
- end
37
- else
38
- raise 'Invalid option'
23
+ if league
24
+ league_table
25
+ elsif team
26
+ if players
27
+ team_players
28
+ elsif fixtures
29
+ team_fixtures
39
30
  end
40
- else
41
- raise 'Invalid command'
42
31
  end
43
32
  end
44
33
 
45
34
  def league_table
46
35
  response = client.league_table(league_id, match_day: match_day)
47
36
 
48
- display(
37
+ output(
49
38
  title: response[:leagueCaption],
50
39
  response: response[:standing],
51
40
  columns: %i(position teamName playedGames goalDifference points),
@@ -57,7 +46,7 @@ module FootballCli
57
46
  response = client.team_players(team_id)
58
47
  team_response = client.team(team_id)
59
48
 
60
- display(
49
+ output(
61
50
  title: "#{team_response[:name]} players. Total #{response[:count]}",
62
51
  response: response[:players],
63
52
  columns: %i(jerseyNumber name position nationality dateOfBirth)
@@ -68,7 +57,7 @@ module FootballCli
68
57
  response = client.team_fixtures(team_id)
69
58
  team_response = client.team(team_id)
70
59
 
71
- display(
60
+ output(
72
61
  title: "#{team_response[:name]} players. Total #{response[:count]}",
73
62
  response: response[:fixtures],
74
63
  columns: %i(matchday homeTeamName goalsHomeTeam goalsAwayTeam awayTeamName status date)
@@ -78,7 +67,7 @@ module FootballCli
78
67
  def live_scores
79
68
  response = client.live_scores
80
69
 
81
- display(
70
+ output(
82
71
  title: 'Live scores',
83
72
  response: response[:games],
84
73
  columns: %i(league homeTeamName goalsHomeTeam goalsAwayTeam awayTeamName time)
@@ -101,24 +90,17 @@ module FootballCli
101
90
  get_qualification(league)
102
91
  end
103
92
 
104
- def display(opts = {})
105
- response = opts[:response]
106
- title = opts[:title]
107
- columns = opts[:columns]
108
- qualification = opts[:qualification]
109
-
110
- factory = FootballCli::Format::FormatFactory.build(
93
+ def output(opts = {})
94
+ FootballCli::Format::FormatFactory.build(
111
95
  format,
112
96
  {
113
- response: response,
114
- title: title,
115
- columns: columns,
116
- file_name: file,
117
- qualification: qualification
97
+ qualification: opts[:qualification],
98
+ response: opts[:response],
99
+ columns: opts[:columns],
100
+ title: opts[:title],
101
+ file_name: file
118
102
  }
119
- )
120
-
121
- factory.output
103
+ ).output
122
104
  end
123
105
 
124
106
  def client
@@ -1,3 +1,3 @@
1
1
  module FootballCli
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Said Kaldybaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: football_ruby
14
+ name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rainbow
28
+ name: football_ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,13 +39,13 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: rainbow
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: aruba
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: terminal-table
70
+ name: aruba
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: gli
84
+ name: terminal-table
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 2.16.0
90
- type: :runtime
89
+ version: '0'
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 2.16.0
96
+ version: '0'
97
97
  description: A command line interface for all the football data feeds in Ruby
98
98
  email:
99
99
  - said.kaldybaev@gmail.com
@@ -113,6 +113,7 @@ files:
113
113
  - config/teams.json
114
114
  - football_cli.gemspec
115
115
  - lib/football_cli.rb
116
+ - lib/football_cli/cli.rb
116
117
  - lib/football_cli/format/base.rb
117
118
  - lib/football_cli/format/csv.rb
118
119
  - lib/football_cli/format/format_factory.rb