Class: Infostrada::Table

Inherits:
BaseRequest show all
Includes:
Enumerable
Defined in:
lib/infostrada/table.rb

Constant Summary collapse

URL =
'/GetTable'

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(phase_id = nil, table_list = [], &block) ⇒ Table

Returns a new instance of Table.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/infostrada/table.rb', line 26

def initialize(phase_id = nil, table_list = [], &block)
  @phase_id = phase_id

  @entries = []
  table_list.each do |hash|
    @edition_id ||= hash['n_EditionID']
    @entries << TableEntry.new(hash) if hash['n_TeamID']
  end

  block.call(self) if block_given?
  self
end

Instance Attribute Details

#edition_idObject

Returns the value of attribute edition_id.



5
6
7
# File 'lib/infostrada/table.rb', line 5

def edition_id
  @edition_id
end

#entriesObject

Returns the value of attribute entries.



5
6
7
# File 'lib/infostrada/table.rb', line 5

def entries
  @entries
end

#phase_idObject

Returns the value of attribute phase_id.



5
6
7
# File 'lib/infostrada/table.rb', line 5

def phase_id
  @phase_id
end

Class Method Details

.from_json(json = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/infostrada/table.rb', line 16

def self.from_json(json = {})
  self.new do |table|
    table.phase_id    = json['phase_id']
    table.edition_id  = json['edition_id']
    table.entries     = json['entries'].map{ |entry|
      TableEntry.from_json(entry)
    }
  end
end

.where(options = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/infostrada/table.rb', line 9

def self.where(options = {})
  phase_id = options.delete(:phase_id)
  list = get!(URL, query: { phaseid: phase_id })

  new(phase_id, list)
end

Instance Method Details

#as_json(options = {}) ⇒ Object



39
40
41
42
# File 'lib/infostrada/table.rb', line 39

def as_json(options = {})
  hash = super
  hash = { 'phase_id' => phase_id, 'edition_id' => edition_id, 'entries' => hash }
end

#each(&block) ⇒ Object



44
45
46
# File 'lib/infostrada/table.rb', line 44

def each(&block)
  @entries.each(&block)
end