Class: SportsDataApi::Ncaafb::Polls

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sports_data_api/ncaafb/polls.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(polls_hash) ⇒ Polls

Returns a new instance of Polls.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sports_data_api/ncaafb/polls.rb', line 7

def initialize(polls_hash)
  @id = polls_hash['id']
  @name = polls_hash['name']
  @season = polls_hash['season']
  @season_type = polls_hash['season_type']
  @week = polls_hash['week']
  @rankings = []
  @candidates = []
  add_poll_teams_to(@rankings, polls_hash['rankings'])
  add_poll_teams_to(@candidates, polls_hash['candidates'])
end

Instance Attribute Details

#candidatesObject (readonly)

Returns the value of attribute candidates.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def candidates
  @candidates
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def name
  @name
end

#rankingsObject (readonly)

Returns the value of attribute rankings.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def rankings
  @rankings
end

#seasonObject (readonly)

Returns the value of attribute season.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def season
  @season
end

#season_typeObject (readonly)

Returns the value of attribute season_type.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def season_type
  @season_type
end

#weekObject (readonly)

Returns the value of attribute week.



6
7
8
# File 'lib/sports_data_api/ncaafb/polls.rb', line 6

def week
  @week
end

Class Method Details

.valid_name?(poll) ⇒ Boolean

Check if the requested poll is a valid Ncaafb poll type.

The only valid polls are: :AP25, :EU25, :CFP25, :FCSC25, :H25, :FCS25

Returns:

  • (Boolean)


37
38
39
# File 'lib/sports_data_api/ncaafb/polls.rb', line 37

def valid_name?(poll)
  [:AP25, :EU25, :CFP25, :FCSC25, :H25, :FCS25].include?(poll.upcase.to_sym)
end

.valid_week?(week) ⇒ Boolean

The only valid week nr is 1..21

Returns:

  • (Boolean)


42
43
44
# File 'lib/sports_data_api/ncaafb/polls.rb', line 42

def valid_week?(week)
  (1..21).include?(week.to_i)
end

Instance Method Details

#each(&block) ⇒ Object

Make the class Enumerable



21
22
23
24
25
26
27
28
29
# File 'lib/sports_data_api/ncaafb/polls.rb', line 21

def each(&block)
  @rankings.each do |team|
    if block_given?
      block.call team
    else
      yield team
    end
  end
end