Class: Bumblebee::Converter

Inherits:
Object
  • Object
show all
Includes:
Types
Defined in:
lib/bumblebee/converter.rb

Overview

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.

Direct Known Subclasses

SimpleConverter

Defined Under Namespace

Modules: Types

Constant Summary collapse

DEFAULT_DATE_FORMAT =
'%Y-%m-%d'
DEFAULT_SEPARATOR =
','

Constants included from Types

Types::BIGDECIMAL, Types::BOOLEAN, Types::DATE, Types::FLOAT, Types::FUNCTION, Types::INTEGER, Types::JOIN, Types::PLUCK_JOIN, Types::PLUCK_SPLIT, Types::SPLIT, Types::STRING

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Converter

Returns a new instance of Converter.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

Instance Attribute Details

#functionObject (readonly)

Returns the value of attribute function.



36
37
38
# File 'lib/bumblebee/converter.rb', line 36

def function
  @function
end

#object_classObject (readonly)

Returns the value of attribute object_class.



36
37
38
# File 'lib/bumblebee/converter.rb', line 36

def object_class
  @object_class
end

#perObject (readonly)

Returns the value of attribute per.



36
37
38
# File 'lib/bumblebee/converter.rb', line 36

def per
  @per
end

#sub_propertyObject (readonly)

Returns the value of attribute sub_property.



36
37
38
# File 'lib/bumblebee/converter.rb', line 36

def sub_property
  @sub_property
end

#typeObject (readonly)

Returns the value of attribute type.



36
37
38
# File 'lib/bumblebee/converter.rb', line 36

def type
  @type
end

Instance Method Details

#convert(val) ⇒ Object



61
62
63
# File 'lib/bumblebee/converter.rb', line 61

def convert(val)
  send("#{VISITOR_METHOD_PREFIX}#{type}", val)
end