Class: Charisma::Characteristic

Inherits:
Object
  • Object
show all
Defined in:
lib/charisma/characteristic.rb

Overview

Stores information about a characteristic.

Typically these are defined with Charisma::Characterization#has in a characterize do . . . end block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, &blk) ⇒ Characteristic

Create a characteristic.

Typically this is done via Charisma::Characterization#has within a characterize do . . . end block.

Parameters:

  • name (Symbol)

    The name of the characteristic. The method with this name will be called on the characterized object to retrieve its raw value.

  • options (Hash)

    The options hash.

  • [Symbol] (Hash)

    a customizable set of options

  • [Class, (Hash)

    a customizable set of options

  • [Proc] (Hash)

    a customizable set of options

See Also:



31
32
33
34
35
36
# File 'lib/charisma/characteristic.rb', line 31

def initialize(name, options, &blk)
  @name = name
  @proc = blk if block_given?
  @accessor = options[:display_with]
  @measurement = options[:measures]
end

Instance Attribute Details

#accessorObject (readonly)

A method that should be called on the characteristic in order to display it properly



15
16
17
# File 'lib/charisma/characteristic.rb', line 15

def accessor
  @accessor
end

#measurementObject (readonly)

Specifies that the characteristic should be treated as a measured quantity



18
19
20
# File 'lib/charisma/characteristic.rb', line 18

def measurement
  @measurement
end

#nameObject (readonly)

The characteristic’s name



9
10
11
# File 'lib/charisma/characteristic.rb', line 9

def name
  @name
end

#procObject (readonly)

A proc, if defined, that specifies how the characteristic should be displayed



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

def proc
  @proc
end

Instance Method Details

#measurement_classClass

The subclass of Charisma::Measurement with which this curation’s characteristic is measured.

Returns:

  • (Class)


40
41
42
43
44
45
46
47
# File 'lib/charisma/characteristic.rb', line 40

def measurement_class
  case measurement
  when ::Class
    measurement
  when ::Symbol
    "::Charisma::Measurement::#{measurement.to_s.camelize}".constantize
  end
end