lib/fitgem/helpers.rb
def label_for_measurement(measurement_type, respect_user_unit_preferences=true)
      unless [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose].include?(measurement_type)
        raise InvalidMeasurementType, "Supplied measurement_type parameter must be one of [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose], current value is :#{measurement_type}"
      end

      selected_unit_system = api_unit_system

      if respect_user_unit_preferences
        unless connected?
          raise ConnectionRequiredError, "No connection to Fitbit API; one is required when passing respect_user_unit_preferences=true"
        end
        # Cache the unit systems for the current user
        @unit_systems ||= self.user_info['user'].select {|key, value| key =~ /Unit$/ }

        case measurement_type
          when :distance
            selected_unit_system = @unit_systems["distanceUnit"]
          when :height
            selected_unit_system = @unit_systems["heightUnit"]
          when :liquids
            selected_unit_system = @unit_systems["waterUnit"]
          when :weight
            selected_unit_system = @unit_systems["weightUnit"]
          when :blood_glucose
            selected_unit_system = @unit_systems["glucoseUnit"]
          else
            selected_unit_system = api_unit_system
        end
      end

      # Fix the METRIC system difference
      selected_unit_system = Fitgem::ApiUnitSystem.METRIC if selected_unit_system == "METRIC"

      # Ensure the target unit system is one that we know about
      unless [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC].include?(selected_unit_system)
        raise InvalidUnitSystem, "The select unit system must be one of [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC], current value is #{selected_unit_system}"
      end

      unit_mappings[selected_unit_system][measurement_type]
    end
# Fetch the correct label for the desired measurement unit.
#
# The general use case for this method is that you are using the client for
# a specific user, and wish to get the correct labels for the unit measurements
# returned for that user.
#
# A secondary use case is that you wish to get the label for a measurement given a unit
# system that you supply (by setting the Fitgem::Client.api_unit_system attribute).
#
# In order for this method to get the correct value for the current user's preferences,
# the client must have the ability to make API calls.  If you respect_user_unit_preferences
# is passed as 'true' (or left as the default value) and the client cannot make API calls
# then an error will be raised by the method.
#
# @param [Symbol] measurement_type The measurement type to fetch the label for
# @param [Boolean] respect_user_unit_preferences Should the method fetch the current user's
#   specific measurement preferences and use those (true), or use the value set on Fitgem::Client.api_unit_system (false)
# @raise [Fitgem::ConnectionRequiredError] Raised when respect_user_unit_preferences is true but the
#   client is not capable of making API calls.
# @raise [Fitgem::InvalidUnitSystem] Raised when the current value of Fitgem::Client.api_unit_system
#   is not one of [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC]
# @raise [Fitgem::InvalidMeasurementType] Raised when the supplied measurement_type is not one of
#   [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose]
# @return [String] The string label corresponding to the measurement type and
#   current api_unit_system.
Fetch the correct label for the desired measurement unit.
The general use case for this method is that you are using the client for
a specific user, and wish to get the correct labels for the unit measurements
returned for that user.

A secondary use case is that you wish to get the label for a measurement given a unit
system that you supply (by setting the Fitgem::Client.api_unit_system attribute).

In order for this method to get the correct value for the current user's preferences,
the client must have the ability to make API calls.  If you respect_user_unit_preferences
is passed as 'true' (or left as the default value) and the client cannot make API calls
then an error will be raised by the method.
Fetch the correct label for the desired measurement unit . The general use case for this method is that you are using the client for a specific user and wish to get the correct labels for the unit measurements returned for that user . A secondary use case is that you wish to get the label for a measurement given a unit system that you supply ( by setting the Fitgem :: Client . api_unit_system attribute ) . In order for this method to get the correct value for the current user ' s preferences the client must have the ability to make API calls . If you respect_user_unit_preferences is passed as ' true ' ( or left as the default value ) and the client cannot make API calls then an error will be raised by the method .
def label_for_measurement(measurement_type, respect_user_unit_preferences=true)
      unless [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose].include?(measurement_type)
        raise InvalidMeasurementType, "Supplied measurement_type parameter must be one of [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose], current value is :#{measurement_type}"
      end
      selected_unit_system = api_unit_system
      if respect_user_unit_preferences
        unless connected?
          raise ConnectionRequiredError, "No connection to Fitbit API; one is required when passing respect_user_unit_preferences=true"
        end
        @unit_systems ||= self.user_info['user'].select {|key, value| key =~ /Unit$/ }
        case measurement_type
          when :distance
            selected_unit_system = @unit_systems["distanceUnit"]
          when :height
            selected_unit_system = @unit_systems["heightUnit"]
          when :liquids
            selected_unit_system = @unit_systems["waterUnit"]
          when :weight
            selected_unit_system = @unit_systems["weightUnit"]
          when :blood_glucose
            selected_unit_system = @unit_systems["glucoseUnit"]
          else
            selected_unit_system = api_unit_system
        end
      end
      selected_unit_system = Fitgem::ApiUnitSystem.METRIC if selected_unit_system == "METRIC"
      unless [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC].include?(selected_unit_system)
        raise InvalidUnitSystem, "The select unit system must be one of [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC], current value is #{selected_unit_system}"
      end
      unit_mappings[selected_unit_system][measurement_type]
    end
def label_for_measurement ( measurement_type , respect_user_unit_preferences = true ) unless [ :duration , :distance , :elevation , :height , :weight , :measurements , :liquids , :blood_glucose ] . include? ( measurement_type ) raise InvalidMeasurementType , "Supplied measurement_type parameter must be one of [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose], current value is :#{measurement_type}" end selected_unit_system = api_unit_system if respect_user_unit_preferences unless connected? raise ConnectionRequiredError , "No connection to Fitbit API; one is required when passing respect_user_unit_preferences=true" end @unit_systems ||= self . user_info [ 'user' ] . select { | key , value | key =~ / Unit$ / } case measurement_type when :distance selected_unit_system = @unit_systems [ "distanceUnit" ] when :height selected_unit_system = @unit_systems [ "heightUnit" ] when :liquids selected_unit_system = @unit_systems [ "waterUnit" ] when :weight selected_unit_system = @unit_systems [ "weightUnit" ] when :blood_glucose selected_unit_system = @unit_systems [ "glucoseUnit" ] else selected_unit_system = api_unit_system end end selected_unit_system = Fitgem :: ApiUnitSystem . METRIC if selected_unit_system == "METRIC" unless [ ApiUnitSystem . US , ApiUnitSystem . UK , ApiUnitSystem . METRIC ] . include? ( selected_unit_system ) raise InvalidUnitSystem , "The select unit system must be one of [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC], current value is #{selected_unit_system}" end unit_mappings [ selected_unit_system ] [ measurement_type ] end
Fetch the correct label for the desired measurement unit.
Fetch the correct label for the desired measurement unit .
# Cache the unit systems for the current user # Fix the METRIC system difference # Ensure the target unit system is one that we know about
The string label corresponding to the measurement type and current api_unit_system.
The string label corresponding to the measurement type and current api_unit_system .
String
[Fitgem::ConnectionRequiredError] Raised when respect_user_unit_preferences is true but the client is not capable of making API calls.
[ Fitgem :: ConnectionRequiredError ] Raised when respect_user_unit_preferences is true but the client is not capable of making API calls .
[Fitgem::InvalidUnitSystem] Raised when the current value of Fitgem::Client.api_unit_system is not one of [ApiUnitSystem.US, ApiUnitSystem.UK, ApiUnitSystem.METRIC]
[ Fitgem :: InvalidUnitSystem ] Raised when the current value of Fitgem :: Client . api_unit_system is not one of [ ApiUnitSystem . US ApiUnitSystem . UK ApiUnitSystem . METRIC ]
[Fitgem::InvalidMeasurementType] Raised when the supplied measurement_type is not one of [:duration, :distance, :elevation, :height, :weight, :measurements, :liquids, :blood_glucose]
[ Fitgem :: InvalidMeasurementType ] Raised when the supplied measurement_type is not one of [ : duration : distance : elevation : height : weight : measurements : liquids : blood_glucose ]
measurement_type
respect_user_unit_preferences
respect_user_unit_preferences Should the method fetch the current user's specific measurement preferences and use those (true), or use the value set on Fitgem::Client.api_unit_system (false)
respect_user_unit_preferences Should the method fetch the current user ' s specific measurement preferences and use those ( true ) or use the value set on Fitgem :: Client . api_unit_system ( false )