Class: Drillbit::Parameters::Sort
- Inherits:
-
Object
- Object
- Drillbit::Parameters::Sort
- Defined in:
- lib/drillbit/parameters/sort.rb
Constant Summary collapse
- DESCENDING_PREFIX =
'-'
Instance Attribute Summary collapse
-
#raw_parameters ⇒ Object
Returns the value of attribute raw_parameters.
Instance Method Summary collapse
-
#initialize(raw_parameters) ⇒ Sort
constructor
A new instance of Sort.
- #present? ⇒ Boolean
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(raw_parameters) ⇒ Sort
Returns a new instance of Sort.
10 11 12 |
# File 'lib/drillbit/parameters/sort.rb', line 10 def initialize(raw_parameters) self.raw_parameters = raw_parameters ? raw_parameters.split(',') : [] end |
Instance Attribute Details
#raw_parameters ⇒ Object
Returns the value of attribute raw_parameters.
8 9 10 |
# File 'lib/drillbit/parameters/sort.rb', line 8 def raw_parameters @raw_parameters end |
Instance Method Details
#present? ⇒ Boolean
14 15 16 |
# File 'lib/drillbit/parameters/sort.rb', line 14 def present? raw_parameters.any? end |
#to_a ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/drillbit/parameters/sort.rb', line 22 def to_a @to_a ||= raw_parameters.map do |raw_parameter| if raw_parameter.start_with?(DESCENDING_PREFIX) [raw_parameter[1..-1], 'desc'] else [raw_parameter, 'asc'] end end end |
#to_h ⇒ Object
18 19 20 |
# File 'lib/drillbit/parameters/sort.rb', line 18 def to_h @to_h ||= Hash[to_a] end |