Class: Hashematics::Type

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/hashematics/type.rb', line 22

def name
  @name
end

#object_classObject (readonly)

Returns the value of attribute object_class.



22
23
24
# File 'lib/hashematics/type.rb', line 22

def object_class
  @object_class
end

#propertiesObject (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_typeObject



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