Class: SortDescriptorLiteral::SortDescriptor
- Inherits:
-
Object
- Object
- SortDescriptorLiteral::SortDescriptor
- Defined in:
- lib/PredicateLiteralKit4Ruby.rb
Instance Attribute Summary collapse
-
#ascending ⇒ Object
readonly
Returns the value of attribute ascending.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
Class Method Summary collapse
Instance Method Summary collapse
- #build_arel(arel_table) ⇒ Object
-
#initialize(key, selector, ascending) ⇒ SortDescriptor
constructor
A new instance of SortDescriptor.
- #underscore(camel_cased_word) ⇒ Object
Constructor Details
#initialize(key, selector, ascending) ⇒ SortDescriptor
Returns a new instance of SortDescriptor.
56 57 58 59 60 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 56 def initialize(key, selector, ascending) @key = key @selector = selector @ascending = ascending end |
Instance Attribute Details
#ascending ⇒ Object (readonly)
Returns the value of attribute ascending.
50 51 52 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 50 def ascending @ascending end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
50 51 52 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 50 def key @key end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
50 51 52 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 50 def selector @selector end |
Class Method Details
.parse(array) ⇒ Object
52 53 54 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 52 def self.parse(array) self.new(array[0], array[1], array[2]) end |
Instance Method Details
#build_arel(arel_table) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 70 def build_arel(arel_table) key = underscore(@key) unless (key = LITERAL_KEY_MAPPING[@key]) key = key.to_sym puts "KEY: #{key}" return arel_table[key].asc if @ascending return arel_table[key].desc end |
#underscore(camel_cased_word) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/PredicateLiteralKit4Ruby.rb', line 62 def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |