Class: JSONAPIonify::Api::SortField
- Inherits:
-
Object
- Object
- JSONAPIonify::Api::SortField
- Defined in:
- lib/jsonapionify/api/sort_field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #contains_arel ⇒ Object
- #contains_operator ⇒ Object
- #id? ⇒ Boolean
-
#initialize(name) ⇒ SortField
constructor
A new instance of SortField.
- #outside_arel ⇒ Object
- #outside_operator ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ SortField
Returns a new instance of SortField.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jsonapionify/api/sort_field.rb', line 6 def initialize(name) @str = name.to_s if name.to_s.start_with? '-' @name = name.to_s[1..-1].to_sym @order = :desc else @name = name.to_sym @order = :asc end freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/jsonapionify/api/sort_field.rb', line 4 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/jsonapionify/api/sort_field.rb', line 4 def order @order end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 21 |
# File 'lib/jsonapionify/api/sort_field.rb', line 18 def ==(other) other.class == self.class && other.name == self.name end |
#===(other) ⇒ Object
23 24 25 26 |
# File 'lib/jsonapionify/api/sort_field.rb', line 23 def ===(other) other.class == self.class && other.name == self.name end |
#contains_arel ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/jsonapionify/api/sort_field.rb', line 41 def contains_arel case @order when :asc :gteq when :desc :lteq end end |
#contains_operator ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/jsonapionify/api/sort_field.rb', line 32 def contains_operator case @order when :asc :>= when :desc :<= end end |
#id? ⇒ Boolean
28 29 30 |
# File 'lib/jsonapionify/api/sort_field.rb', line 28 def id? name == :id end |
#outside_arel ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/jsonapionify/api/sort_field.rb', line 59 def outside_arel case @order when :asc :gt when :desc :lt end end |
#outside_operator ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/jsonapionify/api/sort_field.rb', line 50 def outside_operator case @order when :asc :> when :desc :< end end |
#to_h ⇒ Object
72 73 74 |
# File 'lib/jsonapionify/api/sort_field.rb', line 72 def to_h { name => order } end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/jsonapionify/api/sort_field.rb', line 68 def to_s @str end |