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 = {}, &block) ⇒ Phase

Returns a new instance of Phase.



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
# File 'lib/infostrada/phase.rb', line 53

def initialize(hash = {}, &block)
  @id          = hash['n_PhaseID']
  @name        = hash['c_Phase']
  @level       = hash['n_PhaseLevel']
  @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

  block.call(self) if block_given?
  self
end

Instance Attribute Details

#currentObject

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



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

def current
  @current
end

#currentsObject

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



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

def currents
  @currents
end

#end_dateObject

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



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

def end_date
  @end_date
end

#has_tableObject

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



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

def has_table
  @has_table
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

#levelObject

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



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

def level
  @level
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

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_name
  @phase3_name
end

#short_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 short_name
  @short_name
end

#start_dateObject

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



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

def start_date
  @start_date
end

#tableObject

Get the classification table for this phase.



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

def table
  @table
end

Class Method Details

.from_json(json = {}) ⇒ Object

Useful method to get a Phase object from a json serialized Phase object.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/infostrada/phase.rb', line 33

def self.from_json(json = {})
  new do |phase|
    phase.id          = json['id']
    phase.name        = json['name']
    phase.level       = json['level']
    phase.short_name  = json['short_name']
    phase.phase1_id   = json['phase1_id']
    phase.phase1_name = json['phase1_name']
    phase.phase2_id   = json['phase2_id']
    phase.phase2_name = json['phase2_name']
    phase.phase3_id   = json['phase3_id']
    phase.phase3_name = json['phase3_name']
    phase.has_table   = json['has_table']
    phase.current     = json['current']
    phase.currents    = json['currents']
    phase.start_date  = Date.parse(json['start_date'].to_s) if json['start_date']
    phase.end_date    = Date.parse(json['end_date'].to_s)  if json['end_date']
  end
end

.where(options = {}) ⇒ Object



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

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

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

  list.map do |phase_hash|
    Phase.new(phase_hash)
  end
end

Instance Method Details

#has_table?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/infostrada/phase.rb', line 85

def has_table?
  @has_table
end