Class: Lafcadio::Query::Max

Inherits:
Lafcadio::Query show all
Defined in:
lib/lafcadio/query/Max.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Lafcadio::Query

ASC, DESC

Instance Attribute Summary collapse

Attributes inherited from Lafcadio::Query

#condition, #limit, #objectType, #orderBy, #orderByOrder

Instance Method Summary collapse

Methods inherited from Lafcadio::Query

And, Or, #eql?, #hash, #limitClause, #orderClause, #sqlPrimaryKeyField, #tables, #toSql, #whereClause

Constructor Details

#initialize(objectType, field_name = nil) ⇒ Max

Returns a new instance of Max.



6
7
8
9
10
11
12
13
14
15
# File 'lib/lafcadio/query/Max.rb', line 6

def initialize( objectType, field_name = nil )
	super( objectType )
	if field_name
		@field_name = field_name
		@pk = false
	else
		@field_name = objectType.sqlPrimaryKeyName
		@pk = true
	end
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



4
5
6
# File 'lib/lafcadio/query/Max.rb', line 4

def field_name
  @field_name
end

Instance Method Details

#collect(coll) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/lafcadio/query/Max.rb', line 17

def collect( coll )
	max = nil
	fn = @pk ? 'pkId': @field_name
	coll.each { |d_obj|
		a_value = d_obj.send( fn )
		max = a_value if max.nil? || a_value > max
	}
	[ max ]
end

#fieldsObject



27
28
29
# File 'lib/lafcadio/query/Max.rb', line 27

def fields
	"max(#{ @field_name })"
end