Class: Sports::Butler::Base
- Inherits:
-
Object
- Object
- Sports::Butler::Base
- Defined in:
- lib/sports/butler/base.rb
Direct Known Subclasses
Constant Summary collapse
- ALIASES =
{ areas: :countries, leagues: :competitions, events: :matches, fixtures: :matches, top_scorers: :scorers }
- AVAILABLE_ENDPOINTS =
{ soccer: {}, basketball: {} }
Instance Attribute Summary collapse
-
#api_class ⇒ Object
Returns the value of attribute api_class.
-
#api_name ⇒ Object
Returns the value of attribute api_name.
-
#available_endpoints ⇒ Object
Returns the value of attribute available_endpoints.
-
#endpoints ⇒ Object
Returns the value of attribute endpoints.
-
#sport ⇒ Object
Returns the value of attribute sport.
-
#sport_class ⇒ Object
Returns the value of attribute sport_class.
-
#valid_configuration ⇒ Object
Returns the value of attribute valid_configuration.
Instance Method Summary collapse
-
#initialize(sport:, api_name:) ⇒ Base
constructor
A new instance of Base.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(sport:, api_name:) ⇒ Base
Returns a new instance of Base.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sports/butler/base.rb', line 64 def initialize(sport:, api_name:) @sport = sport @api_name = api_name @api_class = api_name.to_s.camelize @sport_class = "#{sport.to_s.camelize}Api" @endpoints = {} @available_endpoints = get_available_endpoints @valid_configuration = !Configuration.invalid_config?(sport, api_name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/sports/butler/base.rb', line 76 def method_missing(method, *args, &block) endpoint_name = eval_endpoint_name(method) if endpoint_name.present? @endpoints[method].present? ? @endpoints[method] : @endpoints[method] = build_endpoint_classes(endpoint_name) else raise MissingEndpoint, endpoint_not_available(method) end end |
Instance Attribute Details
#api_class ⇒ Object
Returns the value of attribute api_class.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def api_class @api_class end |
#api_name ⇒ Object
Returns the value of attribute api_name.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def api_name @api_name end |
#available_endpoints ⇒ Object
Returns the value of attribute available_endpoints.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def available_endpoints @available_endpoints end |
#endpoints ⇒ Object
Returns the value of attribute endpoints.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def endpoints @endpoints end |
#sport ⇒ Object
Returns the value of attribute sport.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def sport @sport end |
#sport_class ⇒ Object
Returns the value of attribute sport_class.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def sport_class @sport_class end |
#valid_configuration ⇒ Object
Returns the value of attribute valid_configuration.
61 62 63 |
# File 'lib/sports/butler/base.rb', line 61 def valid_configuration @valid_configuration end |