Class: GeneralUnits::Base::Unit
- Inherits:
-
Object
- Object
- GeneralUnits::Base::Unit
- Defined in:
- lib/general_units/units/base/unit.rb
Direct Known Subclasses
Constant Summary collapse
- METRIC_SYSTEMS =
[:metric, :english, :american]
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#fractional ⇒ Object
readonly
Returns the value of attribute fractional.
-
#owner_class ⇒ Object
readonly
Returns the value of attribute owner_class.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
Instance Method Summary collapse
-
#initialize(owner_class, code, fractional, system = :metric) ⇒ Unit
constructor
A new instance of Unit.
- #inspect ⇒ Object
- #to_s(*args) ⇒ Object
Constructor Details
#initialize(owner_class, code, fractional, system = :metric) ⇒ Unit
Returns a new instance of Unit.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/general_units/units/base/unit.rb', line 9 def initialize(owner_class, code, fractional, system = :metric) @owner_class = owner_class @code = code @fractional = fractional.to_d @system = system.to_sym METRIC_SYSTEMS.each do |s| class_eval do define_method "#{s}?" do self.system == s end end end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/general_units/units/base/unit.rb', line 6 def code @code end |
#fractional ⇒ Object (readonly)
Returns the value of attribute fractional.
6 7 8 |
# File 'lib/general_units/units/base/unit.rb', line 6 def fractional @fractional end |
#owner_class ⇒ Object (readonly)
Returns the value of attribute owner_class.
6 7 8 |
# File 'lib/general_units/units/base/unit.rb', line 6 def owner_class @owner_class end |
#system ⇒ Object (readonly)
Returns the value of attribute system.
6 7 8 |
# File 'lib/general_units/units/base/unit.rb', line 6 def system @system end |
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/general_units/units/base/unit.rb', line 30 def inspect code end |
#to_s(*args) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/general_units/units/base/unit.rb', line 23 def to_s(*args) = args. [:format] ||= :long [:count] ||= 1 i18n_key(code.to_sym, ) end |