Class: Nexter::Model::ParseOrder
- Inherits:
-
Object
- Object
- Nexter::Model::ParseOrder
- Defined in:
- lib/nexter/model/parse_order.rb
Instance Attribute Summary collapse
-
#order_values ⇒ Object
readonly
Returns the value of attribute order_values.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(order_values) ⇒ ParseOrder
constructor
A new instance of ParseOrder.
- #parse ⇒ Object
- #parse_arel(arel) ⇒ Object
-
#parse_string(string) ⇒ Object
helper to turn mixed order attributes to a consistant array of vals.
Constructor Details
#initialize(order_values) ⇒ ParseOrder
Returns a new instance of ParseOrder.
9 10 11 |
# File 'lib/nexter/model/parse_order.rb', line 9 def initialize(order_values) @order_values = order_values end |
Instance Attribute Details
#order_values ⇒ Object (readonly)
Returns the value of attribute order_values.
3 4 5 |
# File 'lib/nexter/model/parse_order.rb', line 3 def order_values @order_values end |
Class Method Details
.parse(order_values) ⇒ Object
5 6 7 |
# File 'lib/nexter/model/parse_order.rb', line 5 def self.parse(order_values) new(order_values).parse end |
Instance Method Details
#parse ⇒ Object
14 15 16 17 18 |
# File 'lib/nexter/model/parse_order.rb', line 14 def parse order_values.flat_map do |value| value.is_a?(String) ? parse_string(value) : parse_arel(value) end end |
#parse_arel(arel) ⇒ Object
29 30 31 |
# File 'lib/nexter/model/parse_order.rb', line 29 def parse_arel(arel) [["#{arel.value.name}", "#{arel.direction}"]] end |
#parse_string(string) ⇒ Object
helper to turn mixed order attributes to a consistant array of vals
21 22 23 24 25 26 27 |
# File 'lib/nexter/model/parse_order.rb', line 21 def parse_string(string) string.split(",").map(&:strip).map do |column| splits = column.split(" ").map(&:strip).map(&:downcase) splits << "asc" if splits.size == 1 splits end end |