Class: Cacofonix::Formatters

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

Class Method Summary collapse

Class Method Details

.booleanObject



50
51
52
# File 'lib/cacofonix.rb', line 50

def self.boolean
  lambda { |val| ""  if val }
end

.decimalObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cacofonix.rb', line 10

def self.decimal
  lambda do |val|
    if val.nil?
      nil
    elsif val.kind_of?(BigDecimal)
      val.to_s("F")
    else
      val.to_s
    end
  end
end

.space_separatedObject



46
47
48
# File 'lib/cacofonix.rb', line 46

def self.space_separated
  lambda { |val| [val.collect(&:to_s).join(" ")]  if val }
end

.two_digitObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cacofonix.rb', line 32

def self.two_digit
  lambda do |val|
    if val.nil?
      nil
    elsif val < 10
      "0#{val}"
    elsif val > 99
      val.to_s[-2,2]
    else
      val.to_s
    end
  end
end

.yyyymmddObject



22
23
24
25
26
27
28
29
30
# File 'lib/cacofonix.rb', line 22

def self.yyyymmdd
  lambda do |val|
    if val.nil? || !val.respond_to?(:strftime)
      nil
    else
      val.strftime("%Y%m%d")
    end
  end
end