Class: FootballCli::Format::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/football_cli/format/base.rb

Direct Known Subclasses

Csv, Json, Table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
# File 'lib/football_cli/format/base.rb', line 6

def initialize(opts={})
  @response = opts[:response]
  @title = opts[:title]
  @columns = opts[:columns]
  @file_name = opts[:file_name]
  @qualification = opts[:qualification]

  @rows = []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/football_cli/format/base.rb', line 4

def columns
  @columns
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/football_cli/format/base.rb', line 4

def response
  @response
end

#rowsObject (readonly)

Returns the value of attribute rows.



4
5
6
# File 'lib/football_cli/format/base.rb', line 4

def rows
  @rows
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/football_cli/format/base.rb', line 4

def title
  @title
end

Instance Method Details

#generateObject

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/football_cli/format/base.rb', line 16

def generate
  raise NotImplementedError, 'must implement generate() method in subclass'
end

#goal_columnsObject



28
29
30
# File 'lib/football_cli/format/base.rb', line 28

def goal_columns
  %i(goalsHomeTeam goalsAwayTeam).freeze
end

#outputObject



20
21
22
23
24
25
26
# File 'lib/football_cli/format/base.rb', line 20

def output
  if @file_name
    File.write(@file_name, generate)
  else
    puts generate
  end
end

#qualificationObject



32
33
34
# File 'lib/football_cli/format/base.rb', line 32

def qualification
  Hash[@qualification.collect {|k, v| [ k, v.each_cons(2).map {|from, to| from..to }.max ] }] if @qualification
end