Class: Smalltime::Unit
- Inherits:
-
Object
- Object
- Smalltime::Unit
- Defined in:
- lib/smalltime.rb
Instance Attribute Summary collapse
-
#multiplier ⇒ Object
readonly
Returns the value of attribute multiplier.
-
#shortname ⇒ Object
readonly
Returns the value of attribute shortname.
Instance Method Summary collapse
- #*(other) ⇒ Object
-
#initialize(singular_name, plural_name, shortname, base: 1, multiplier: 1) ⇒ Unit
constructor
Initialize a new unit with the given names, equal to the given base unit multiplied by the given multiplier.
- #inspect ⇒ Object
- #name ⇒ Object
- #names ⇒ Object
- #pluralize ⇒ Object (also: #plural)
- #to_sym ⇒ Object
Constructor Details
#initialize(singular_name, plural_name, shortname, base: 1, multiplier: 1) ⇒ Unit
Initialize a new unit with the given names, equal to the given base unit multiplied by the given multiplier.
44 45 46 47 48 49 50 |
# File 'lib/smalltime.rb', line 44 def initialize(singular_name, plural_name, shortname, base: 1, multiplier: 1) @singular_name = singular_name @plural_name = plural_name @shortname = shortname @base = base @multiplier = multiplier end |
Instance Attribute Details
#multiplier ⇒ Object (readonly)
Returns the value of attribute multiplier.
60 61 62 |
# File 'lib/smalltime.rb', line 60 def multiplier @multiplier end |
#shortname ⇒ Object (readonly)
Returns the value of attribute shortname.
60 61 62 |
# File 'lib/smalltime.rb', line 60 def shortname @shortname end |
Instance Method Details
#*(other) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/smalltime.rb', line 52 def *(other) if other.is_a?(Numeric) return @base * @multiplier * other end (@base * @multiplier) * (other.base * other.multiplier) end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/smalltime.rb', line 86 def inspect "#<Smalltime::#{@plural_name}>" end |
#name ⇒ Object
66 67 68 |
# File 'lib/smalltime.rb', line 66 def name @singular_name end |
#names ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/smalltime.rb', line 75 def names [ @singular_name.to_s, @plural_name.to_s, @shortname.to_s, @singular_name.to_sym, @plural_name.to_sym, @shortname.to_sym ] end |
#pluralize ⇒ Object Also known as: plural
70 71 72 |
# File 'lib/smalltime.rb', line 70 def pluralize @plural_name end |
#to_sym ⇒ Object
62 63 64 |
# File 'lib/smalltime.rb', line 62 def to_sym @plural_name.to_sym end |