Class: Lafcadio::Query::Max
- Inherits:
-
Lafcadio::Query
- Object
- Lafcadio::Query
- Lafcadio::Query::Max
- Defined in:
- lib/lafcadio/query/Max.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Lafcadio::Query
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
Attributes inherited from Lafcadio::Query
#condition, #limit, #objectType, #orderBy, #orderByOrder
Instance Method Summary collapse
- #collect(coll) ⇒ Object
- #fields ⇒ Object
-
#initialize(objectType, field_name = nil) ⇒ Max
constructor
A new instance of Max.
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_name ⇒ Object (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 |
#fields ⇒ Object
27 28 29 |
# File 'lib/lafcadio/query/Max.rb', line 27 def fields "max(#{ @field_name })" end |