Class: Momomoto::Order::Lower

Inherits:
Momomoto::Order show all
Defined in:
lib/momomoto/order.rb

Overview

This class is used for case-insensitive orders. It is derived from the Order class where you can find more information on usage.

Instance Attribute Summary

Attributes inherited from Momomoto::Order

#fields

Instance Method Summary collapse

Methods inherited from Momomoto::Order

#to_sql

Constructor Details

#initialize(*fields) ⇒ Lower

Creates a new instance of Lower and flattens the given parameter fields. Raises Error if presented with fields that are either instances of Order::Asc or Order::Desc.

Usage:

Momomoto::Order::Lower.new(:author, [:title, :publisher])


77
78
79
80
81
82
83
# File 'lib/momomoto/order.rb', line 77

def initialize( *fields )
  fields = fields.flatten
  fields.each do | field |
    raise Error, "Asc and Desc are only allowed as toplevel order elements" if field.kind_of?( Asc ) or field.kind_of?( Desc )
  end
  @fields = fields
end

Instance Method Details

#function(argument) ⇒ Object

Translates all +argument+s to the SQL statement. Returns the joined arguments.



87
88
89
90
91
# File 'lib/momomoto/order.rb', line 87

def function( argument )
  argument = [ argument ] if not argument.kind_of?( Array )
  argument = argument.map{|a| "lower(#{a})"}
  argument.join(',')
end