Sha256: d2dc93ceb4e94d6486efb8e5856aa7ad20245273a0c6dc5c35195791eef5c50c
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true require "./lib/mlb_rb/version" require "./lib/mlb_rb/client" require "./lib/mlb_rb/game" module MlbRb class Error < StandardError; end class DateError < StandardError; end class << self def healthcheck "Yup, everything is fine" end def games_for_date(options) date = options[:date] raise DateError unless validate_date(date) client.get_games_for_date(format_date(date)) end def games_for_date_range(options) start_date = options[:start_date] end_date = options[:end_date] [start_date, end_date].each do |date| raise DateError unless validate_date(date) end client.get_games_for_range(format_date(start_date), format_date(end_date)) end private def format_date(date) "#{"%02d" % date[:month]}/#{"%02d" % date[:day]}/#{date[:year]}" end def validate_date(date) date.map do |key, value| valid_number_for_date(value, key) end.all? end def valid_number_for_date(date_number, type) if type == :year date_number.between?(1876, Date.today.year) elsif type == :month date_number.between?(1, 12) elsif type == :day date_number.between?(1, 31) end end def client MlbRb::Client end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mlb_rb-0.0.3 | lib/mlb_rb.rb |