Sha256: fd4b58d2d10cebb9f9b092178bbc88473bd9ad0b5c6b478a474def6e30b8d405

Contents?: true

Size: 977 Bytes

Versions: 3

Compression:

Stored size: 977 Bytes

Contents

module FitParser
  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.4 lib/fit_parser/file/type.rb
fit_parser-0.0.2 lib/fit_parser/file/type.rb
fit_parser-0.0.1 lib/fit_parser/file/type.rb