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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
Instance Method Summary collapse
-
#initialize(code, name, short, fractional, system = :metric) ⇒ Unit
constructor
A new instance of Unit.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(code, name, short, fractional, system = :metric) ⇒ Unit
Returns a new instance of Unit.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/general_units/units/base/unit.rb', line 8 def initialize(code, name, short, fractional, system = :metric) @code = code @name = name.to_s @short = short.to_s @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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/general_units/units/base/unit.rb', line 6 def name @name end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
6 7 8 |
# File 'lib/general_units/units/base/unit.rb', line 6 def short @short 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
27 28 29 |
# File 'lib/general_units/units/base/unit.rb', line 27 def inspect code end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/general_units/units/base/unit.rb', line 23 def to_s name end |