Sha256: 40705f77842f0f197072df0e9421b96728c79918fa33363156719eb82175587a

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

module Activite
  class Measure < Base

    # Create a new instance.
    #
    # The Withings API returns all values as integers with a unit which represents
    # the power of 10 the value should be multiplied by to get the real value. For
    # example, value=20 and unit=-1 should be 2.0.
    #
    # @param attrs [Hash]
    # @return [Activite::Measure]
    def initialize(attrs = {})
      super(attrs)
      @value = value / (10 ** unit.abs).to_f
    end

    #
    # Different measurement types
    #
    
    Weight = Class.new(self) do |cls|
      # Return weight measurement in kilograms (default unit)
      #
      # @return [Float]
      def in_kg
        @value
      end

      # Return weight measurement in pounds
      #
      # @return [Float]
      def in_lb
        (@value * 2.20462).round(3)
      end
    end
    
    Height = Class.new(self)
    Pulse  = Class.new(self)

    FatFreeMass   = Class.new(Weight)
    FatMassWeight = Class.new(Weight)
    FatRatio      = Class.new(self)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activite-0.2.0 lib/activite/measures.rb
activite-0.1.0 lib/activite/measures.rb