Class: Medidas::DerivedUnit

Inherits:
Unit
  • Object
show all
Defined in:
lib/medidas/derived_unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Unit

#*, #base_unit?, #coerce, #inspect, #name_for, registered_units, #to_s

Constructor Details

#initialize(name:, plural:, base_unit:, factor:) ⇒ DerivedUnit

Returns a new instance of DerivedUnit.



10
11
12
13
14
15
# File 'lib/medidas/derived_unit.rb', line 10

def initialize(name:, plural:, base_unit:, factor: )
  @name   = name
  @plural = plural
  @base_unit = base_unit
  @factor = factor
end

Instance Attribute Details

#base_unitObject (readonly)

Returns the value of attribute base_unit.



3
4
5
# File 'lib/medidas/derived_unit.rb', line 3

def base_unit
  @base_unit
end

#factorObject (readonly)

Returns the value of attribute factor.



4
5
6
# File 'lib/medidas/derived_unit.rb', line 4

def factor
  @factor
end

Class Method Details

.[](name, plural: "#{name}s", base_unit:, factor: 1) ⇒ Object



6
7
8
# File 'lib/medidas/derived_unit.rb', line 6

def self.[](name, plural: "#{name}s", base_unit:, factor: 1)
  registered_units[name] ||= new(name: name, plural: plural, base_unit: base_unit, factor: factor)
end