Class: Peanuts::Converter

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

Overview

Currently supported types:

string

see Convert_string

boolean

see Convert_boolean, Convert_yesno

numeric

see Convert_integer, Convert_decimal, Convert_float

date & time

see Convert_datetime

lists

see Convert_list

Direct Known Subclasses

Convert_list, Convert_string

Defined Under Namespace

Classes: Convert_boolean, Convert_datetime, Convert_decimal, Convert_float, Convert_integer, Convert_list, Convert_string, Convert_yesno

Class Method Summary collapse

Class Method Details

.create(type, options) ⇒ Object



28
29
30
31
32
# File 'lib/peanuts/converters.rb', line 28

def self.create(type, options)
  create!(type, options)
rescue ArgumentError
  nil
end

.create!(type, options) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/peanuts/converters.rb', line 34

def self.create!(type, options)
  case type
  when Symbol
    lookup!(type)
  else
    type
  end.new(options)
end

.lookup(type) ⇒ Object



14
15
16
17
18
# File 'lib/peanuts/converters.rb', line 14

def self.lookup(type)
  lookup!(type)
rescue ArgumentError
  nil
end

.lookup!(type) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/peanuts/converters.rb', line 20

def self.lookup!(type)
  begin
    const_get("Convert_#{type}")
  rescue NameError
    raise ArgumentError, "converter not found for #{type}"
  end
end