Class: Unparser::Anima::Attribute
- Inherits:
-
Object
- Object
- Unparser::Anima::Attribute
- Includes:
- Unparser::Adamantium
- Defined in:
- lib/unparser/anima/attribute.rb
Overview
An attribute
Instance Attribute Summary collapse
-
#instance_variable_name ⇒ Symbol
readonly
Return instance variable name.
-
#name ⇒ Symbol
readonly
Return attribute name.
Instance Method Summary collapse
-
#get(object) ⇒ Object
Get attribute value from object.
-
#initialize(name) ⇒ Attribute
constructor
Initialize attribute.
-
#load(object, attributes) ⇒ self
Load attribute.
-
#set(object, value) ⇒ self
Set attribute value in object.
Constructor Details
#initialize(name) ⇒ Attribute
Initialize attribute
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_name ⇒ Symbol (readonly)
Return instance variable name
25 26 27 |
# File 'lib/unparser/anima/attribute.rb', line 25 def instance_variable_name @instance_variable_name end |
#name ⇒ Symbol (readonly)
Return attribute name
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
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
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
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 |