Class: Structural::Model::TypeCasts::Cast

Inherits:
Object
  • Object
show all
Defined in:
lib/structural/model/type_casts.rb

Direct Known Subclasses

Date, Float, Identity, Integer, Money, Time

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Cast

Returns a new instance of Cast.



21
22
23
# File 'lib/structural/model/type_casts.rb', line 21

def initialize(value)
  @value = value
end

Instance Method Details

#castObject



25
26
27
# File 'lib/structural/model/type_casts.rb', line 25

def cast
  value.is_a?(type) ? value : conversion
end

#conversionObject

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/structural/model/type_casts.rb', line 33

def conversion
  raise NotImplementedError
end

#typeObject



29
30
31
# File 'lib/structural/model/type_casts.rb', line 29

def type
  self.class.type
end