Class: Bumblebee::Converter
- Inherits:
-
Object
- Object
- Bumblebee::Converter
- 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
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
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#object_class ⇒ Object
readonly
Returns the value of attribute object_class.
-
#per ⇒ Object
readonly
Returns the value of attribute per.
-
#sub_property ⇒ Object
readonly
Returns the value of attribute sub_property.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #convert(val) ⇒ Object
-
#initialize(arg) ⇒ Converter
constructor
A new instance of Converter.
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
#function ⇒ Object (readonly)
Returns the value of attribute function.
36 37 38 |
# File 'lib/bumblebee/converter.rb', line 36 def function @function end |
#object_class ⇒ Object (readonly)
Returns the value of attribute object_class.
36 37 38 |
# File 'lib/bumblebee/converter.rb', line 36 def object_class @object_class end |
#per ⇒ Object (readonly)
Returns the value of attribute per.
36 37 38 |
# File 'lib/bumblebee/converter.rb', line 36 def per @per end |
#sub_property ⇒ Object (readonly)
Returns the value of attribute sub_property.
36 37 38 |
# File 'lib/bumblebee/converter.rb', line 36 def sub_property @sub_property end |
#type ⇒ Object (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 |