Class: Infostrada::Phase

Inherits:
BaseRequest show all
Defined in:
lib/infostrada/phase.rb

Overview

Phase of a given edition.

The only thing that can be confusing is the current and currents boolean variables. Here’s an explanation from the Infostrada API website:

* b_Current: this boolean field describes the current phase. This field can be True for only
             one phase.

* b_Currents: this boolean field describes the current phases. More than one phases can be
              True, e.g. multiple groups in the Champions League.

You can only get a list of phases on Infostradas GetPhaseList endpoint.

Constant Summary collapse

URL =
'/GetPhaseList'

Constants inherited from BaseRequest

BaseRequest::RETRIES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRequest

get!

Constructor Details

#initialize(hash) ⇒ Phase

Returns a new instance of Phase.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/infostrada/phase.rb', line 39

def initialize(hash)
  @id = hash['n_PhaseID']
  @name = hash['c_Phase']
  @short_name = hash['c_PhaseShort']
  @phase1_id = hash['n_Phase1ID']
  @phase1_name = hash['c_Phase1']
  @phase2_id = hash['n_Phase2ID']
  @phase2_name = hash['c_Phase2']
  @phase3_id = hash['n_Phase3ID']
  @phase3_name = hash['c_Phase3']
  @has_table = hash['b_Table']
  @current = hash['b_Current']
  @currents = hash['b_Currents']

  # On GetPhaseList endpoint dates are just yyymmdd. Example: 20100629 (which translates to
  # 2010-06-29).
  if hash['n_DateStart'] && hash['n_DateEnd']
    @start_date = Date.parse(hash['n_DateStart'].to_s)
    @end_date = Date.parse(hash['n_DateEnd'].to_s)
  end

  self
end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



19
20
21
# File 'lib/infostrada/phase.rb', line 19

def current
  @current
end

#currentsObject

Returns the value of attribute currents.



19
20
21
# File 'lib/infostrada/phase.rb', line 19

def currents
  @currents
end

#end_dateObject

Returns the value of attribute end_date.



19
20
21
# File 'lib/infostrada/phase.rb', line 19

def end_date
  @end_date
end

#idObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def id
  @id
end

#nameObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def name
  @name
end

#phase1_idObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def phase1_id
  @phase1_id
end

#phase1_nameObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def phase1_name
  @phase1_name
end

#phase2_idObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def phase2_id
  @phase2_id
end

#phase2_nameObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def phase2_name
  @phase2_name
end

#phase3_idObject

Short name is only set outside GetPhaseList endpoint. For example on match list.



18
19
20
# File 'lib/infostrada/phase.rb', line 18

def phase3_id
  @phase3_id
end

#phase3_nameObject

Returns the value of attribute phase3_name.



19
20
21
# File 'lib/infostrada/phase.rb', line 19

def phase3_name
  @phase3_name
end

#short_nameObject

Returns the value of attribute short_name.



19
20
21
# File 'lib/infostrada/phase.rb', line 19

def short_name
  @short_name
end

#start_dateObject

Returns the value of attribute start_date.



19
20
21
# File 'lib/infostrada/phase.rb', line 19

def start_date
  @start_date
end

#tableObject

Get the classification table for this phase.



35
36
37
# File 'lib/infostrada/phase.rb', line 35

def table
  @table
end

Class Method Details

.where(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/infostrada/phase.rb', line 21

def self.where(options = {})
  edition_id = options.delete(:edition_id)

  list = get!(URL, query: { editionid: edition_id.to_i })

  phases = []
  list.each do |phase_hash|
    phases << Phase.new(phase_hash)
  end

  phases
end

Instance Method Details

#has_table?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/infostrada/phase.rb', line 63

def has_table?
  @has_table
end