Class: Charisma::Curator::Curation
- Inherits:
-
Delegator
- Object
- Delegator
- Charisma::Curator::Curation
- 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
-
#characteristic ⇒ Charisma::Characteristic
readonly
The characteristic, as defined in the class’s characterization.
-
#value ⇒ Object
The computed value of the characteristic.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#__getobj__ ⇒ Object
Delegator method.
-
#__setobj__(obj) ⇒ Object
Delegator method.
-
#as_json ⇒ Object
Render a JSON-like object for later conversion to JSON.
-
#initialize(value, characteristic = nil) ⇒ Curation
constructor
Create new Curation wrapper.
-
#inspect ⇒ Object
An inspection method for more readable IRB sessions and logs.
- #u ⇒ Object
- #units ⇒ Object
Constructor Details
#initialize(value, characteristic = nil) ⇒ Curation
Create new Curation wrapper.
This is typically done by the instance’s Charisma::Curator
23 24 25 26 27 |
# File 'lib/charisma/curator/curation.rb', line 23 def initialize(value, characteristic = nil) @characteristic = characteristic establish_units_methods self.value = value end |
Instance Attribute Details
#characteristic ⇒ Charisma::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 |
#value ⇒ Object
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 34 35 |
# File 'lib/charisma/curator/curation.rb', line 31 def ==(other) a = self.value b = other.respond_to?(:value) ? other.value : other a == b end |
#__getobj__ ⇒ Object
Delegator method
47 |
# File 'lib/charisma/curator/curation.rb', line 47 def __getobj__; value end |
#__setobj__(obj) ⇒ Object
Delegator method
50 |
# File 'lib/charisma/curator/curation.rb', line 50 def __setobj__(obj); self.value = obj end |
#as_json ⇒ Object
Render a JSON-like object for later conversion to JSON
61 62 63 64 65 66 67 68 69 |
# File 'lib/charisma/curator/curation.rb', line 61 def as_json(*) if characteristic.measurement characteristic.measurement_class.new(value).as_json elsif value.respond_to? :as_json value.as_json else value end end |
#inspect ⇒ Object
An inspection method for more readable IRB sessions and logs.
38 39 40 41 42 43 44 |
# File 'lib/charisma/curator/curation.rb', line 38 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 |
#u ⇒ Object
56 57 58 |
# File 'lib/charisma/curator/curation.rb', line 56 def u characteristic.try(:measurement_class).try(:unit_abbreviation) end |
#units ⇒ Object
52 53 54 |
# File 'lib/charisma/curator/curation.rb', line 52 def units characteristic.try(:measurement_class).try(:unit) end |