Sha256: ab5801c6a57ffe66910dc68a2e8edf9eca2d6f63819a66c7779a19da0fbd35bb

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

module FitParser
  class File
    class Type
      def self.types
        @types ||= {}
      end

      def self.types=(value)
        @types = value
      end

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

      def initialize(type)
        @type = type
      end

      def value(val)
        return nil unless valid?(val)
        if @type.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 valid?(val)
        if @type.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

13 entries across 13 versions & 1 rubygems

Version Path
fit_parser-1.0.9 lib/fit_parser/file/type.rb
fit_parser-1.0.8 lib/fit_parser/file/type.rb
fit_parser-1.0.7 lib/fit_parser/file/type.rb
fit_parser-1.0.6 lib/fit_parser/file/type.rb
fit_parser-1.0.5 lib/fit_parser/file/type.rb
fit_parser-1.0.4 lib/fit_parser/file/type.rb
fit_parser-1.0.3 lib/fit_parser/file/type.rb
fit_parser-1.0.2 lib/fit_parser/file/type.rb
fit_parser-1.0.1 lib/fit_parser/file/type.rb
fit_parser-1.0.0 lib/fit_parser/file/type.rb
fit_parser-0.0.8 lib/fit_parser/file/type.rb
fit_parser-0.0.7 lib/fit_parser/file/type.rb
fit_parser-0.0.6 lib/fit_parser/file/type.rb