Sha256: 9d181257c99f5ad3bb89eb95b620b2769dd6e87d877d9aaa4f5a9fd05ef6f17c

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module SleeperRb
  module Resources
    class League
      class Roster
        ##
        # Settings for a specific roster in a league, including W/L/D, scoring_data, and waiver info.
        class Settings
          include SleeperRb::Utilities::Cache

          ##
          # :attr_reader: wins

          ##
          # :attr_reader: waiver_position

          ##
          # :attr_reader: waiver_budget_used

          ##
          # :attr_reader: total_moves

          ##
          # :attr_reader: ties

          ##
          # :attr_reader: losses

          ##
          # :attr_reader: fpts_decimal

          ##
          # :attr_reader: fpts_against_decimal

          ##
          # :attr_reader: fpts_against

          ##
          # :attr_reader: fpts

          cached_attr :wins, :waiver_position, :waiver_budget_used, :total_moves, :ties, :losses, :fpts_decimal,
                      :fpts_against_decimal, :fpts_against, :fpts

          skip_refresh :all

          ##
          # @return [Float] All points scored by the roster
          def total_points
            (fpts.to_f + (fpts_decimal.to_f * 0.01)).round(2)
          end

          ##
          # @return [Float] All points scored against the roster
          def total_points_against
            (fpts_against.to_f + (fpts_against_decimal.to_f * 0.01)).round(2)
          end

          ##
          # @return [Float] Percentage of games won by the roster
          def win_pct
            return 0.0 unless [wins, ties, losses].any?(&:positive?)

            ((wins.to_f / (wins + ties + losses)) * 100.0).round(2)
          end

          ##
          # @return [String] Record for the roster in W - L - T format
          def record_string
            "#{wins} - #{losses} - #{ties}"
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sleeper_rb-0.2.1 lib/sleeper_rb/resources/league/roster/settings.rb
sleeper_rb-0.2.0 lib/sleeper_rb/resources/league/roster/settings.rb