Sha256: 40479642cc68535b77fae7181a6b0a8ff33b572651b4222eae5032307b41aed9

Contents?: true

Size: 971 Bytes

Versions: 3

Compression:

Stored size: 971 Bytes

Contents

module Fit
  class File
    class Type

      @@types = {}

      def self.get_type(name)
        return @@types[name] if @@types.has_key? name
        type = Types.get_type_definition name
        @@types[name] = type ? new(type) : nil
      end

      def initialize(type)
        @type = type
      end

      def value(val)
        return nil unless is_valid(val)
        if @type.has_key? :method
          Types.send(@type[:method], val, @type[:values], @type[:parameters])
        else
          values = @type[:values]
          value = values[val] if values
          return value unless value.nil?
          val
        end
      end

      private
        def is_valid(val)
          if @type.has_key? :invalid
            invalid_value = @type[:invalid]
          else
            invalid_value = Types.get_type_definition(@type[:basic_type])[:invalid]
          end
          return false if val == invalid_value
          true
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fit-parser-0.0.3 lib/fit/file/type.rb
fit-parser-0.0.2 lib/fit/file/type.rb
fit-parser-0.0.1 lib/fit/file/type.rb