Sha256: 00ee806e37a2026a396877f3a451730d5af490c7c8990cda75fd6d4e03c40e2f

Contents?: true

Size: 494 Bytes

Versions: 104

Compression:

Stored size: 494 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

104 entries across 104 versions & 1 rubygems

Version Path
renalware-core-2.0.159 app/values/renalware/bmi.rb
renalware-core-2.0.158 app/values/renalware/bmi.rb
renalware-core-2.0.157 app/values/renalware/bmi.rb
renalware-core-2.0.156 app/values/renalware/bmi.rb
renalware-core-2.0.155 app/values/renalware/bmi.rb
renalware-core-2.0.153 app/values/renalware/bmi.rb
renalware-core-2.0.152 app/values/renalware/bmi.rb
renalware-core-2.0.151 app/values/renalware/bmi.rb
renalware-core-2.0.149 app/values/renalware/bmi.rb
renalware-core-2.0.148 app/values/renalware/bmi.rb
renalware-core-2.0.147 app/values/renalware/bmi.rb
renalware-core-2.0.146 app/values/renalware/bmi.rb
renalware-core-2.0.145 app/values/renalware/bmi.rb
renalware-core-2.0.144 app/values/renalware/bmi.rb
renalware-core-2.0.143 app/values/renalware/bmi.rb
renalware-core-2.0.142 app/values/renalware/bmi.rb
renalware-core-2.0.141 app/values/renalware/bmi.rb
renalware-core-2.0.140 app/values/renalware/bmi.rb
renalware-core-2.0.139 app/values/renalware/bmi.rb
renalware-core-2.0.138 app/values/renalware/bmi.rb