Sha256: cc5c9308116e65d53bc115619439a334e18b6d12788cc9e1578ba57aa52b418f

Contents?: true

Size: 493 Bytes

Versions: 28

Compression:

Stored size: 493 Bytes

Contents

# frozen_string_literal: true

require "attr_extras"

module Renalware
  # Value object representing Body Mass Index. Accepts only meters and kg
  #
  # Example usage:
  #   bmi = Renalware::BMI.new(height: 1.80, weight: 180)
  #   bmi.to_f # => 55.6
  #   bmi.to_s # => "55.6"
  #
  class BMI
    pattr_initialize [:weight!, :height!]
    delegate :to_s, to: :to_f

    def to_f
      return unless weight && height && height > 0
      ((weight / height) / height).round(1)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/values/renalware/bmi.rb
renalware-core-2.0.45 app/values/renalware/bmi.rb
renalware-core-2.0.44 app/values/renalware/bmi.rb
renalware-core-2.0.43 app/values/renalware/bmi.rb
renalware-core-2.0.42 app/values/renalware/bmi.rb
renalware-core-2.0.41 app/values/renalware/bmi.rb
renalware-core-2.0.40 app/values/renalware/bmi.rb
renalware-core-2.0.39 app/values/renalware/bmi.rb
renalware-core-2.0.38 app/values/renalware/bmi.rb
renalware-core-2.0.37 app/values/renalware/bmi.rb
renalware-core-2.0.36 app/values/renalware/bmi.rb
renalware-core-2.0.35 app/values/renalware/bmi.rb
renalware-core-2.0.34 app/values/renalware/bmi.rb
renalware-core-2.0.33 app/values/renalware/bmi.rb
renalware-core-2.0.32 app/values/renalware/bmi.rb
renalware-core-2.0.31 app/values/renalware/bmi.rb
renalware-core-2.0.30 app/values/renalware/bmi.rb
renalware-core-2.0.28 app/values/renalware/bmi.rb
renalware-core-2.0.27 app/values/renalware/bmi.rb
renalware-core-2.0.26 app/values/renalware/bmi.rb