Class: Cacofonix::Formatters
- Inherits:
-
Object
- Object
- Cacofonix::Formatters
- Defined in:
- lib/cacofonix.rb
Class Method Summary collapse
- .boolean ⇒ Object
- .decimal ⇒ Object
- .space_separated ⇒ Object
- .two_digit ⇒ Object
- .yyyymmdd ⇒ Object
Class Method Details
.boolean ⇒ Object
50 51 52 |
# File 'lib/cacofonix.rb', line 50 def self.boolean lambda { |val| "" if val } end |
.decimal ⇒ Object
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_separated ⇒ Object
46 47 48 |
# File 'lib/cacofonix.rb', line 46 def self.space_separated lambda { |val| [val.collect(&:to_s).join(" ")] if val } end |
.two_digit ⇒ Object
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 |
.yyyymmdd ⇒ Object
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 |