sferik/mlb-ruby

View on GitHub
lib/mlb/season.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
require "equalizer"
require "shale"
require_relative "league"
require_relative "sport"

module MLB
  class Season < Shale::Mapper
    include Comparable
    include Equalizer.new(:id)

    attribute :id, Shale::Type::Integer
    attribute :has_wildcard, Shale::Type::Boolean
    attribute :preseason_start_date, Shale::Type::Date
    attribute :preseason_end_date, Shale::Type::Date
    attribute :season_start_date, Shale::Type::Date
    attribute :spring_start_date, Shale::Type::Date
    attribute :spring_end_date, Shale::Type::Date
    attribute :regular_season_start_date, Shale::Type::Date
    attribute :last_date_first_half, Shale::Type::Date
    attribute :all_star_date, Shale::Type::Date
    attribute :first_date_second_half, Shale::Type::Date
    attribute :regular_season_end_date, Shale::Type::Date
    attribute :postseason_start_date, Shale::Type::Date
    attribute :postseason_end_date, Shale::Type::Date
    attribute :season_end_date, Shale::Type::Date
    attribute :offseason_start_date, Shale::Type::Date
    attribute :offseason_end_date, Shale::Type::Date
    attribute :season_level_gameday_type, Shale::Type::String
    attribute :game_level_gameday_type, Shale::Type::String
    attribute :qualifier_plate_appearances, Shale::Type::Float
    attribute :qualifier_outs_pitched, Shale::Type::Float

    alias_method :wildcard?, :has_wildcard

    json do
      map "seasonId", to: :id
      map "hasWildcard", to: :has_wildcard
      map "preSeasonStartDate", to: :preseason_start_date
      map "preSeasonEndDate", to: :preseason_end_date
      map "seasonStartDate", to: :season_start_date
      map "springStartDate", to: :spring_start_date
      map "springEndDate", to: :spring_end_date
      map "regularSeasonStartDate", to: :regular_season_start_date
      map "lastDate1stHalf", to: :last_date_first_half
      map "allStarDate", to: :all_star_date
      map "firstDate2ndHalf", to: :first_date_second_half
      map "regularSeasonEndDate", to: :regular_season_end_date
      map "postSeasonStartDate", to: :postseason_start_date
      map "postSeasonEndDate", to: :postseason_end_date
      map "seasonEndDate", to: :season_end_date
      map "offseasonStartDate", to: :offseason_start_date
      map "offSeasonEndDate", to: :offseason_end_date
      map "seasonLevelGamedayType", to: :season_level_gameday_type
      map "gameLevelGamedayType", to: :game_level_gameday_type
      map "qualifierPlateAppearances", to: :qualifier_plate_appearances
      map "qualifierOutsPitched", to: :qualifier_outs_pitched
    end

    def <=>(other)
      id <=> other.id
    end
  end
end