Class: YFantasy::PickemTeam

Inherits:
BaseResource show all
Defined in:
lib/y_fantasy/resources/pickem_team.rb,
lib/y_fantasy/resources/pickem_team/pick.rb,
lib/y_fantasy/resources/pickem_team/week_pick.rb

Overview

Represents a Yahoo Fantasy Pick’em Team in a NFL Survival Group

Defined Under Namespace

Classes: Pick, WeekPick

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

collection_name, dependent?, find, find_all, resource_name

Methods included from Subresourceable

included

Instance Attribute Details

#can_edit_current_weekBoolean? (readonly)

Returns whether picks are editable for the current week.

Returns:

  • (Boolean, nil)

    whether picks are editable for the current week



32
# File 'lib/y_fantasy/resources/pickem_team.rb', line 32

option :can_edit_current_week, optional: true, type: Types::Params::Bool

#current_pickString? (readonly)

Returns the current pick for this team.

Returns:

  • (String, nil)

    the current pick for this team



36
# File 'lib/y_fantasy/resources/pickem_team.rb', line 36

option :current_pick, optional: true

#current_picksArray? (readonly)

Returns the current picks for this team.

Returns:

  • (Array, nil)

    the current picks for this team



40
# File 'lib/y_fantasy/resources/pickem_team.rb', line 40

option :current_picks, optional: true

#eliminatedBoolean? (readonly)

Returns whether this team has been eliminated.

Returns:

  • (Boolean, nil)

    whether this team has been eliminated



44
# File 'lib/y_fantasy/resources/pickem_team.rb', line 44

option :eliminated, optional: true, type: Types::Params::Bool

#elimination_pickString? (readonly)

Returns the pick that caused this team’s elimination.

Returns:

  • (String, nil)

    the pick that caused this team’s elimination



48
# File 'lib/y_fantasy/resources/pickem_team.rb', line 48

option :elimination_pick, optional: true

#elimination_weekInteger (readonly)

Returns The week number when this team was eliminated.

Returns:

  • (Integer)

    The week number when this team was eliminated



26
# File 'lib/y_fantasy/resources/pickem_team.rb', line 26

option :elimination_week, type: Types::Coercible::Integer

#is_in_contestBoolean? (readonly)

Returns whether this team is in a contest.

Returns:

  • (Boolean, nil)

    whether this team is in a contest



52
# File 'lib/y_fantasy/resources/pickem_team.rb', line 52

option :is_in_contest, optional: true, type: Types::Params::Bool

#is_owned_by_current_loginBoolean? (readonly)

Returns whether this team is owned by the current user.

Returns:

  • (Boolean, nil)

    whether this team is owned by the current user



56
# File 'lib/y_fantasy/resources/pickem_team.rb', line 56

option :is_owned_by_current_login, optional: true, type: Types::Params::Bool

#last_editable_weekString? (readonly)

Returns the last week number that can be edited.

Returns:

  • (String, nil)

    the last week number that can be edited



60
# File 'lib/y_fantasy/resources/pickem_team.rb', line 60

option :last_editable_week, optional: true

#managerTeam::Manager? (readonly)

Returns the manager of this PickemTeam.

Returns:



64
# File 'lib/y_fantasy/resources/pickem_team.rb', line 64

option :manager, optional: true, type: instance_of(Team::Manager)

#nameString (readonly)

Returns The name of the PickemTeam.

Returns:

  • (String)

    The name of the PickemTeam



18
# File 'lib/y_fantasy/resources/pickem_team.rb', line 18

option :name

#statusString? (readonly)

Returns the status of this PickemTeam.

Returns:

  • (String, nil)

    the status of this PickemTeam



68
# File 'lib/y_fantasy/resources/pickem_team.rb', line 68

option :status, optional: true

#team_idInteger (readonly)

Returns The ID for this PickemTeam.

Returns:

  • (Integer)

    The ID for this PickemTeam



14
# File 'lib/y_fantasy/resources/pickem_team.rb', line 14

option :team_id, type: Types::Coercible::Integer

#team_keyString (readonly)

Returns The unique key for this PickemTeam.

Returns:

  • (String)

    The unique key for this PickemTeam



10
# File 'lib/y_fantasy/resources/pickem_team.rb', line 10

option :team_key

#total_strikesInteger (readonly)

Returns The total number of strikes this team has.

Returns:

  • (Integer)

    The total number of strikes this team has



22
# File 'lib/y_fantasy/resources/pickem_team.rb', line 22

option :total_strikes, type: Types::Coercible::Integer

#week_picksArray<WeekPick>? (readonly)

Returns the weekly picks for this team.

Returns:

  • (Array<WeekPick>, nil)

    the weekly picks for this team



74
# File 'lib/y_fantasy/resources/pickem_team.rb', line 74

option :week_picks, optional: true, type: array_of(WeekPick)

Instance Method Details

#groupGroup

Returns the group this PickemTeam belongs to

Returns:

  • (Group)

    the group object



94
95
96
# File 'lib/y_fantasy/resources/pickem_team.rb', line 94

def group
  @group ||= Group.find(group_key, with: :settings)
end

#group_keyString

Returns the group key for this PickemTeam

Returns:

  • (String)

    the group key



88
89
90
# File 'lib/y_fantasy/resources/pickem_team.rb', line 88

def group_key
  @group_key ||= team_key.sub(/\.t\.\d+/, "")
end

#keyString

Returns the key of this PickemTeam

Returns:

  • (String)

    the team key



82
83
84
# File 'lib/y_fantasy/resources/pickem_team.rb', line 82

def key
  team_key
end

#true_total_strikesInteger

Returns the “true” total strikes, based on the group end week. If the group allows two picks per week, fall back to ‘total_strikes` from the PickemTeam.

Returns:

  • (Integer)

    the “true” total strikes for this team



108
109
110
111
112
113
114
115
# File 'lib/y_fantasy/resources/pickem_team.rb', line 108

def true_total_strikes
  return total_strikes if group.settings.two_pick_start_week != 0

  strikes = true_week_picks.count { |wp| wp&.picks&.first&.result == "strike" }
  return group.settings.max_strikes if strikes > group.settings.max_strikes

  strikes
end

#true_week_picksArray<WeekPick>

Returns the week picks up to and including the group end week For some reason, Yahoo’s API can return more weeks than the group settings allow, and they are always strikes.

Returns:

  • (Array<WeekPick>)

    the weekly picks for this team



101
102
103
# File 'lib/y_fantasy/resources/pickem_team.rb', line 101

def true_week_picks
  @true_week_picks = week_picks&.slice(0, group.settings.end_week)
end