Class: Hashematics::Type
- Inherits:
-
Object
- Object
- Hashematics::Type
- Defined in:
- lib/hashematics/type.rb
Overview
A Type defines an object.
Constant Summary collapse
- HASH_VALUE =
'hash'
- OPEN_STRUCT_VALUE =
'open_struct'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#object_class ⇒ Object
readonly
Returns the value of attribute object_class.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(object, child_hash = {}) ⇒ Object
-
#initialize(name: '', properties: nil, object_class: nil) ⇒ Type
constructor
A new instance of Type.
Constructor Details
#initialize(name: '', properties: nil, object_class: nil) ⇒ Type
Returns a new instance of Type.
24 25 26 27 28 29 30 |
# File 'lib/hashematics/type.rb', line 24 def initialize(name: '', properties: nil, object_class: nil) @name = name @properties = make_properties(properties) @object_class = object_class || HASH_VALUE freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/hashematics/type.rb', line 22 def name @name end |
#object_class ⇒ Object (readonly)
Returns the value of attribute object_class.
22 23 24 |
# File 'lib/hashematics/type.rb', line 22 def object_class @object_class end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
22 23 24 |
# File 'lib/hashematics/type.rb', line 22 def properties @properties end |
Class Method Details
.null_type ⇒ Object
14 15 16 |
# File 'lib/hashematics/type.rb', line 14 def null_type @null_type ||= new end |
Instance Method Details
#convert(object, child_hash = {}) ⇒ Object
32 33 34 |
# File 'lib/hashematics/type.rb', line 32 def convert(object, child_hash = {}) make_object(to_hash(object).merge(child_hash)) end |