Class: Rose::Attribute::Sort

Inherits:
Object
  • Object
show all
Defined in:
lib/rose/attribute.rb

Overview

This is a value object for sort parameters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column_name, order, &sort_block) ⇒ Sort

Returns a new instance of Sort.



67
68
69
70
71
# File 'lib/rose/attribute.rb', line 67

def initialize(column_name, order, &sort_block)
  @column_name = column_name
  @order       = order
  @sort_block  = sort_block
end

Instance Attribute Details

#column_nameObject (readonly)

Returns the value of attribute column_name.



65
66
67
# File 'lib/rose/attribute.rb', line 65

def column_name
  @column_name
end

#orderObject (readonly)

Returns the value of attribute order.



65
66
67
# File 'lib/rose/attribute.rb', line 65

def order
  @order
end

#sort_blockObject (readonly)

Returns the value of attribute sort_block.



65
66
67
# File 'lib/rose/attribute.rb', line 65

def sort_block
  @sort_block
end

Instance Method Details

#on(table) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/rose/attribute.rb', line 73

def on(table)
  if @sort_block
    table.sort_rows_by!(nil, :order => @order) do |row|
      @sort_block.call(row[@column_name])
    end
  else
    table.sort_rows_by!(@column_name, :order => @order)
  end
  table
end