Module: Metior::Report::ViewHelper

Included in:
View
Defined in:
lib/metior/report/view_helper.rb

Overview

This helper module implements generic functionality that is included in all report views

Author:

  • Sebastian Staudt

Instance Method Summary collapse

Instance Method Details

#countFixnum

Increases the counter by one and returns it

This can, for example, be used to count the values in an array that is iterated in a view.

Returns:

  • (Fixnum)

    The current counter value

See Also:



21
22
23
24
# File 'lib/metior/report/view_helper.rb', line 21

def count
  @count ||= 0
  @count += 1
end

#even_odd'even', 'odd'

Returns whether the current counter value is even or odd

This is specifically useful for e.g. generating alternating colors of table rows in the output of the view.

Returns:

  • ('even', 'odd')

    'even' if the current counter value is even, 'odd' otherwise.

See Also:



34
35
36
# File 'lib/metior/report/view_helper.rb', line 34

def even_odd
  (count % 2 == 0) ? 'even' : 'odd'
end

#reset_countObject

Resets the current counter to 0

See Also:



41
42
43
# File 'lib/metior/report/view_helper.rb', line 41

def reset_count
  @count = 0
end