Class: Charisma::Measurement Abstract
- Inherits:
-
Object
- Object
- Charisma::Measurement
- Defined in:
- lib/charisma/measurement.rb,
lib/charisma/measurement/time.rb,
lib/charisma/measurement/mass.rb,
lib/charisma/measurement/speed.rb,
lib/charisma/measurement/length.rb
Overview
An actual measurement class should inherit from this and use #units to define units.
An abstract class that implements an API for Charisma to deal with measured characteristics.
Defined Under Namespace
Classes: Length, Mass, Speed, Time
Constant Summary
- Velocity =
Velocity is an SI-accepted alias for speed
Speed
Instance Attribute Summary (collapse)
-
- (Object) value
readonly
The quantity of the measured value.
Class Method Summary (collapse)
-
+ (Symbol) unit
Retrive the units used by the measurement.
-
+ (String) unit_abbreviation
Retrieve the abbreviation of the units used by the measurement.
-
+ (Object) units(units)
Define the units used with this measurement.
Instance Method Summary (collapse)
-
- (Object) as_json
Provide a hash for later conversion to JSON.
-
- (Measurement) initialize(value)
constructor
Create a new instance of this measurement.
-
- (Object) method_missing(*args)
Handle conversion methods.
-
- (Fixnum) to_f
Return just the quantity of the measurement.
-
- (Object) to_hash
Provide a hash form.
-
- (String) to_s
Show the measured value, along with units.
-
- (String) u
The standard abbreviation for the measurement's units.
-
- (Symbol) units
The measurement's units.
Constructor Details
- (Measurement) initialize(value)
Create a new instance of this measurement.
Typically this will be done automatically by Charisma::Curator::Curation.
15 16 17 |
# File 'lib/charisma/measurement.rb', line 15 def initialize(value) @value = value end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(*args)
Handle conversion methods
44 45 46 47 48 49 50 |
# File 'lib/charisma/measurement.rb', line 44 def method_missing(*args) if Conversions.conversions[units.to_sym][args.first] to_f.send(units.to_sym).to(args.first) else super end end |
Instance Attribute Details
- (Object) value (readonly)
The quantity of the measured value
8 9 10 |
# File 'lib/charisma/measurement.rb', line 8 def value @value end |
Class Method Details
+ (Symbol) unit
Retrive the units used by the measurement
73 74 75 |
# File 'lib/charisma/measurement.rb', line 73 def unit @units end |
+ (String) unit_abbreviation
Retrieve the abbreviation of the units used by the measurement
79 80 81 |
# File 'lib/charisma/measurement.rb', line 79 def unit_abbreviation @units_abbreviation end |
+ (Object) units(units)
Define the units used with this measurement.
Used by conforming subclasses.
67 68 69 |
# File 'lib/charisma/measurement.rb', line 67 def units(units) @units, @units_abbreviation = units.to_a.flatten end |
Instance Method Details
- (Object) as_json
Provide a hash for later conversion to JSON
58 59 60 |
# File 'lib/charisma/measurement.rb', line 58 def as_json to_hash end |
- (Fixnum) to_f
Return just the quantity of the measurement
27 28 29 |
# File 'lib/charisma/measurement.rb', line 27 def to_f value.to_f end |
- (Object) to_hash
Provide a hash form
53 54 55 |
# File 'lib/charisma/measurement.rb', line 53 def to_hash { :value => value, :units => units.to_s } end |
- (String) to_s
Show the measured value, along with units
21 22 23 |
# File 'lib/charisma/measurement.rb', line 21 def to_s "#{NumberHelper.delimit value} #{u}" end |
- (String) u
The standard abbreviation for the measurement's units
39 40 41 |
# File 'lib/charisma/measurement.rb', line 39 def u self.class.unit_abbreviation end |
- (Symbol) units
The measurement's units
33 34 35 |
# File 'lib/charisma/measurement.rb', line 33 def units self.class.unit end |