Class: Inflect::AbstractService
- Inherits:
-
Object
- Object
- Inflect::AbstractService
- Includes:
- Comparable, Responsive, Singleton
- Defined in:
- lib/inflect/abstract_service.rb
Overview
Acts as an specification or standard required for a Service Class to be consumed by the application. A Service Class is just a wrapper for any possible service you’d like to give support to, just by having four prerequisites.
Instance Attribute Summary collapse
-
#priority ⇒ Object
readonly
In case there are modules that provide similar contents the one with most
priorityis picked. -
#words ⇒ Object
readonly
A
wordsArray constant with the keywordsof the Service.
Instance Method Summary collapse
-
#<=>(other_service) ⇒ Object
Implement Comparable in order to be sortable.
-
#handle(words) ⇒ Object
Returns a Hash with retrieved data.
-
#initialize ⇒ AbstractService
constructor
A new instance of AbstractService.
-
#valid?(words) ⇒ Boolean
Receives an Array of words and returns true or false depending if the Service can handle the request given by the words.
Methods included from Responsive
Constructor Details
#initialize ⇒ AbstractService
Returns a new instance of AbstractService.
23 24 25 26 |
# File 'lib/inflect/abstract_service.rb', line 23 def initialize @priority = 0 @words = [] end |
Instance Attribute Details
#priority ⇒ Object (readonly)
In case there are modules that provide similar contents the one with most priority is picked.
21 22 23 |
# File 'lib/inflect/abstract_service.rb', line 21 def priority @priority end |
#words ⇒ Object (readonly)
A words Array constant with the key words of the Service.
17 18 19 |
# File 'lib/inflect/abstract_service.rb', line 17 def words @words end |
Instance Method Details
#<=>(other_service) ⇒ Object
Implement Comparable in order to be sortable.
29 30 31 |
# File 'lib/inflect/abstract_service.rb', line 29 def <=> (other_service) priority <=> other_service.priority end |
#handle(words) ⇒ Object
Returns a Hash with retrieved data.
45 46 47 48 49 |
# File 'lib/inflect/abstract_service.rb', line 45 def handle(words) = "#{self.class} must implement handle method, for more information see AbstractService class." raise NoMethodError.new end |
#valid?(words) ⇒ Boolean
Receives an Array of words and returns true or false depending if the Service can handle the request given by the words.
38 39 40 |
# File 'lib/inflect/abstract_service.rb', line 38 def valid?(words) (@words & words).any? end |