Class: Unparser::Anima::Attribute

Inherits:
Object
  • Object
show all
Includes:
Unparser::Adamantium
Defined in:
lib/unparser/anima/attribute.rb

Overview

An attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Attribute

Initialize attribute

Parameters:

  • name (Symbol)


12
13
14
15
# File 'lib/unparser/anima/attribute.rb', line 12

def initialize(name)
  @name = name
  @instance_variable_name = :"@#{name}"
end

Instance Attribute Details

#instance_variable_nameSymbol (readonly)

Return instance variable name

Returns:

  • (Symbol)


25
26
27
# File 'lib/unparser/anima/attribute.rb', line 25

def instance_variable_name
  @instance_variable_name
end

#nameSymbol (readonly)

Return attribute name

Returns:

  • (Symbol)


20
21
22
# File 'lib/unparser/anima/attribute.rb', line 20

def name
  @name
end

Instance Method Details

#get(object) ⇒ Object

Get attribute value from object

Parameters:

  • object (Object)

Returns:

  • (Object)


42
43
44
# File 'lib/unparser/anima/attribute.rb', line 42

def get(object)
  object.public_send(name)
end

#load(object, attributes) ⇒ self

Load attribute

Parameters:

  • object (Object)
  • attributes (Hash)

Returns:

  • (self)


33
34
35
# File 'lib/unparser/anima/attribute.rb', line 33

def load(object, attributes)
  set(object, attributes.fetch(name))
end

#set(object, value) ⇒ self

Set attribute value in object

Parameters:

  • object (Object)
  • value (Object)

Returns:

  • (self)


52
53
54
55
56
# File 'lib/unparser/anima/attribute.rb', line 52

def set(object, value)
  object.instance_variable_set(instance_variable_name, value)

  self
end