Class: Dux::Comparable::Attribute Private
- Inherits:
-
Struct
- Object
- Struct
- Dux::Comparable::Attribute
- Defined in:
- lib/dux/comparable.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Attribute definition with sort ordering.
Instance Attribute Summary collapse
-
#name ⇒ Object
private
Returns the value of attribute name.
-
#order ⇒ Object
private
Returns the value of attribute order.
Instance Method Summary collapse
-
#ascending? ⇒ Boolean
private
Check if the #order is ascending.
-
#descending? ⇒ Boolean
private
Check if the #order is descending.
-
#to_comparison(wrap: false) ⇒ String
private
Generate the comparison expression used to compare this attribute against another.
- #to_inspect(many: false, default: nil) ⇒ String private
Instance Attribute Details
#name ⇒ Object (private)
Returns the value of attribute name
189 190 191 |
# File 'lib/dux/comparable.rb', line 189 def name @name end |
#order ⇒ Object (private)
Returns the value of attribute order
189 190 191 |
# File 'lib/dux/comparable.rb', line 189 def order @order end |
Instance Method Details
#ascending? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the #order is ascending
191 192 193 |
# File 'lib/dux/comparable.rb', line 191 def ascending? order == :asc end |
#descending? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the #order is descending
196 197 198 |
# File 'lib/dux/comparable.rb', line 196 def descending? order == :desc end |
#to_comparison(wrap: false) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate the comparison expression used to compare this attribute against another.
216 217 218 219 220 221 222 223 224 |
# File 'lib/dux/comparable.rb', line 216 def to_comparison(wrap: false) if ascending? "self.#{name} <=> other.#{name}" elsif descending? "other.#{name} <=> self.#{name}" end.tap do |expression| return "(#{expression})" if wrap end end |
#to_inspect(many: false, default: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
204 205 206 207 208 |
# File 'lib/dux/comparable.rb', line 204 def to_inspect(many: false, default: nil) ":#{name}".tap do |s| s << " #{order.to_s.upcase}" unless many && order == default end end |