Class: Pulo::Unit
- Inherits:
-
Object
- Object
- Pulo::Unit
- Defined in:
- lib/pulo/quantity/unit.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
Returns the value of attribute abbreviation.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#plural ⇒ Object
readonly
Returns the value of attribute plural.
Instance Method Summary collapse
-
#initialize(name, plural, abbreviation) ⇒ Unit
constructor
A new instance of Unit.
- #to_s ⇒ Object
Constructor Details
#initialize(name, plural, abbreviation) ⇒ Unit
Returns a new instance of Unit.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pulo/quantity/unit.rb', line 6 def initialize(name, plural, abbreviation) case plural when :s plural=name.to_s + 's' when :sf plural=name.to_s.sub(/(?<=.)_{1}/, 's_') else plural=plural.to_s end @name, @plural, @abbreviation=name, plural, abbreviation end |
Instance Attribute Details
#abbreviation ⇒ Object (readonly)
Returns the value of attribute abbreviation.
5 6 7 |
# File 'lib/pulo/quantity/unit.rb', line 5 def abbreviation @abbreviation end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/pulo/quantity/unit.rb', line 5 def name @name end |
#plural ⇒ Object (readonly)
Returns the value of attribute plural.
5 6 7 |
# File 'lib/pulo/quantity/unit.rb', line 5 def plural @plural end |
Instance Method Details
#to_s ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/pulo/quantity/unit.rb', line 17 def to_s ret=abbreviation.ljust(12,' ') + name.to_s.ljust(30) + plural.ljust(30) if self.is_si? ret+='*10^' + self.scale.round(2).to_s.ljust(7,' ') else ret+=self.si_convert_factor.round(4).to_s + ' per ' + self.si_convert_unit.to_s end ret end |