Class: ESPN::Arguments
- Inherits:
-
Array
- Object
- Array
- ESPN::Arguments
- Defined in:
- lib/espn/arguments.rb
Overview
Internal: Extract options from method arguments.
Constant Summary
Constants included from Mapper
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Public: Gets the options Hash.
Instance Method Summary collapse
-
#initialize(args, defaults = {}, required = []) ⇒ Arguments
constructor
Public: Initialize an instance of Arguments.
Methods included from Helpers
Methods included from Mapper
#extract_sport_and_league, #league?, #map_league_to_sport, #sport?
Constructor Details
#initialize(args, defaults = {}, required = []) ⇒ Arguments
Public: Initialize an instance of Arguments.
args - The Array of arguments passed into a method. defaults - The Hash of default values for the options (default: {}). required - The Array of fields that are required (default: []).
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/espn/arguments.rb', line 19 def initialize(args, defaults={}, required=[]) @options = args.last.is_a?(::Hash) ? args.pop : {} # Set defaults, only if the value in @options is nil. @options.merge!(defaults) { |k, v1, v2| v1 } # Extract sport and league @options[:sport], @options[:league] = extract_sport_and_league(args, @options) # Validate required fields required.each do |field| if blank?(@options[field.to_sym]) raise ArgumentError, "You must supply a valid #{field}." end end super(args) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Public: Gets the options Hash.
12 13 14 |
# File 'lib/espn/arguments.rb', line 12 def @options end |