Module: Cowtech::RubyOnRails::Helpers::FormatHelper

Defined in:
app/helpers/cowtech/ruby_on_rails/helpers/format_helper.rb

Instance Method Summary collapse

Instance Method Details

#currency_class(currency, include_positive = true, include_zero = true) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/cowtech/ruby_on_rails/helpers/format_helper.rb', line 23

def currency_class(currency, include_positive = true, include_zero = true)
	color = ""

	if currency > 0 then
		color = "positive" if include_positive
	elsif currency < 0 then
		color = "negative"
	else
		color = "zero" if include_zero
	end

	"class=\"numeric #{color}\""
end

#format_field(field, default = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/cowtech/ruby_on_rails/helpers/format_helper.rb', line 11

def format_field(field, default = nil)
	if field.is_a?(Fixnum) then
		field
	elsif field.is_a?(Float) then
		field.format_number
	elsif field.blank? || field.strip.blank? then
		(default ? default : "Not set")
	else
		field
	end
end

#text_class(val, additional = nil) ⇒ Object



37
38
39
# File 'app/helpers/cowtech/ruby_on_rails/helpers/format_helper.rb', line 37

def text_class(val, additional = nil)
	"class=\"text #{additional.blank? ? nil : additional} #{val.blank? ? "unset" : nil}\""
end