Class: CastedHash::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/casted_hash/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, casted_hash) ⇒ Value

Returns a new instance of Value.



7
8
9
10
# File 'lib/casted_hash/value.rb', line 7

def initialize(value, casted_hash)
  @value = value
  @casted_hash = casted_hash
end

Instance Attribute Details

#casted_hashObject

Returns the value of attribute casted_hash.



5
6
7
# File 'lib/casted_hash/value.rb', line 5

def casted_hash
  @casted_hash
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/casted_hash/value.rb', line 4

def value
  @value
end

Instance Method Details

#cast!Object



21
22
23
24
25
26
# File 'lib/casted_hash/value.rb', line 21

def cast!
  return if casted?

  @value = casted_hash.cast_proc.call(value)
  @casted = true
end

#casted?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/casted_hash/value.rb', line 17

def casted?
  !!@casted
end

#casted_valueObject



12
13
14
15
# File 'lib/casted_hash/value.rb', line 12

def casted_value
  cast!
  @value
end