Class: Charisma::Curator::Curation

Inherits:
Delegator
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/charisma/curator/curation.rb

Overview

A wrapper around computed characteristic values that intervenes when the value is asked to present itself.

Implements the Delegator pattern, with uncaught methods delegated to the characteristic’s computed value. (Undocumented below is that #to_s is specifically delegated to #render.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, characteristic = nil) ⇒ Curation

Create new Curation wrapper.

This is typically done by the instance’s Charisma::Curator

Parameters:

  • value

    The computed value of the characteristic for the instance

  • characteristic (Charisma::Characteristic, optional) (defaults to: nil)

    The associated characteristic definition



23
24
25
26
27
# File 'lib/charisma/curator/curation.rb', line 23

def initialize(value, characteristic = nil)
  @characteristic = characteristic
  establish_units_methods if characteristic && characteristic.measurement
  self.value = value
end

Instance Attribute Details

#characteristicCharisma::Characteristic (readonly)

The characteristic, as defined in the class’s characterization



16
17
18
# File 'lib/charisma/curator/curation.rb', line 16

def characteristic
  @characteristic
end

#valueObject

The computed value of the characteristic



12
13
14
# File 'lib/charisma/curator/curation.rb', line 12

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/charisma/curator/curation.rb', line 31

def ==(other)
  self.value == other.value
end

#__getobj__Object

Delegator method



45
# File 'lib/charisma/curator/curation.rb', line 45

def __getobj__; value end

#__setobj__(obj) ⇒ Object

Delegator method



48
# File 'lib/charisma/curator/curation.rb', line 48

def __setobj__(obj); self.value = obj end

#inspectObject

An inspection method for more readable IRB sessions and logs.



36
37
38
39
40
41
42
# File 'lib/charisma/curator/curation.rb', line 36

def inspect
  if characteristic
    "<Charisma::Curator::Curation for :#{characteristic.name} (use #to_s to render value of #{value.class})>"
  else
    "<Charisma::Curator::Curation for undefined characteristic (use #to_s to render value of #{value.class})>"
  end          
end