Class: Smalltime::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/smalltime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#multiplierObject (readonly)

Returns the value of attribute multiplier.



60
61
62
# File 'lib/smalltime.rb', line 60

def multiplier
  @multiplier
end

#shortnameObject (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

#inspectObject



86
87
88
# File 'lib/smalltime.rb', line 86

def inspect
  "#<Smalltime::#{@plural_name}>"
end

#nameObject



66
67
68
# File 'lib/smalltime.rb', line 66

def name
  @singular_name
end

#namesObject



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

#pluralizeObject Also known as: plural



70
71
72
# File 'lib/smalltime.rb', line 70

def pluralize
  @plural_name
end

#to_symObject



62
63
64
# File 'lib/smalltime.rb', line 62

def to_sym
  @plural_name.to_sym
end