Class: SmoothOperator::InternalAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/smooth_operator/internal_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, type, turn_to_open_struct = nil) ⇒ InternalAttribute

Returns a new instance of InternalAttribute.



9
10
11
12
13
14
15
# File 'lib/smooth_operator/internal_attribute.rb', line 9

def initialize(name, value, type, turn_to_open_struct = nil)
  @original_name, @original_value, @type = name, value, type
  
  @turn_unknown_hash_to_open_struct = turn_to_open_struct.nil? ? true : turn_to_open_struct

  @first_value = set_value(value)
end

Instance Attribute Details

#first_valueObject (readonly)

Returns the value of attribute first_value.



7
8
9
# File 'lib/smooth_operator/internal_attribute.rb', line 7

def first_value
  @first_value
end

#original_nameObject (readonly)

Returns the value of attribute original_name.



7
8
9
# File 'lib/smooth_operator/internal_attribute.rb', line 7

def original_name
  @original_name
end

#original_valueObject (readonly)

Returns the value of attribute original_value.



7
8
9
# File 'lib/smooth_operator/internal_attribute.rb', line 7

def original_value
  @original_value
end

#turn_unknown_hash_to_open_structObject (readonly)

Returns the value of attribute turn_unknown_hash_to_open_struct.



7
8
9
# File 'lib/smooth_operator/internal_attribute.rb', line 7

def turn_unknown_hash_to_open_struct
  @turn_unknown_hash_to_open_struct
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/smooth_operator/internal_attribute.rb', line 7

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/smooth_operator/internal_attribute.rb', line 7

def value
  @value
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/smooth_operator/internal_attribute.rb', line 21

def changed?
  @first_value != @value
end

#set_value(new_value) ⇒ Object



17
18
19
# File 'lib/smooth_operator/internal_attribute.rb', line 17

def set_value(new_value)
  @value = cast_to_type(new_value)
end

#wasObject



25
26
27
# File 'lib/smooth_operator/internal_attribute.rb', line 25

def was
  @first_value
end