class Bumblebee::Converter
Base class that defines the general interface and structure for a converter class. Subclasses should use the 'visitor' pattern and imeplement a visit_* method for each of the Types
.
Constants
- DEFAULT_DATE_FORMAT
- DEFAULT_SEPARATOR
- VISITOR_METHOD_PREFIX
Attributes
function[R]
object_class[R]
per[R]
resolver[R]
sub_property[R]
type[R]
Public Class Methods
new(arg)
click to toggle source
# File lib/bumblebee/converter.rb, line 42 def initialize(arg) if arg.is_a?(Proc) @type = FUNCTION @function = arg @object_class = Hash elsif arg.is_a?(Hash) hash = arg.symbolize_keys initialize_from_hash(hash) else @type = make_type(arg) @per = make_converter @object_class = Hash end @resolver = Objectable.resolver freeze end
Public Instance Methods
convert(val)
click to toggle source
# File lib/bumblebee/converter.rb, line 61 def convert(val) send("#{VISITOR_METHOD_PREFIX}#{type}", val) end
Private Instance Methods
date_format()
click to toggle source
# File lib/bumblebee/converter.rb, line 93 def date_format @date_format || DEFAULT_DATE_FORMAT end
initialize_from_hash(hash)
click to toggle source
# File lib/bumblebee/converter.rb, line 73 def initialize_from_hash(hash) @type = make_type(hash[:type]) @function = hash[:function] @nullable = hash[:nullable] @separator = hash[:separator] @date_format = hash[:date_format] @sub_property = hash[:sub_property] @object_class = hash[:object_class] || Hash @per = make_converter(hash[:per]) end
make_converter(arg = nil)
click to toggle source
# File lib/bumblebee/converter.rb, line 97 def make_converter(arg = nil) arg ? self.class.new(arg) : NullConverter.new end
make_type(val)
click to toggle source
# File lib/bumblebee/converter.rb, line 69 def make_type(val) Types.const_get(val.to_s.upcase.to_sym) end
nullable()
click to toggle source
# File lib/bumblebee/converter.rb, line 84 def nullable @nullable || false end
Also aliased as: nullable?
separator()
click to toggle source
# File lib/bumblebee/converter.rb, line 89 def separator @separator || DEFAULT_SEPARATOR end