Sha256: 2a5e81360f22d79a9775fc62dcb8f400977d442ffecb44e937995bc65b8ee3a4

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

Contents

require 'activite/measures'

module Activite
  class MeasurementGroup < Base
    # Types of body measurements collected by Withings devices and supported
    # by this gem. See http://oauth.withings.com/api/doc#api-Measure-get_measure
    # for details.
    TYPES = {
      1  => Activite::Measure::Weight,
      4  => Activite::Measure::Height,
      5  => Activite::Measure::FatFreeMass,
      6  => Activite::Measure::FatRatio,
      8  => Activite::Measure::FatMassWeight,
      11 => Activite::Measure::Pulse
    }

    # Create a new instance with a collection of measurements of the appropriate
    # Activite::Measure type.
    #
    # @param attrs [Hash]
    # @return [Activite::MeasurementGroup]
    def initialize(attrs = {})
      super(attrs)
      return if attrs['measures'].nil?
      @measures = attrs['measures'].collect do |measurement|
        klass = TYPES[measurement['type']]
        klass.new(measurement) unless klass.nil?
      end.reject { |obj| obj.nil? }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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