Sha256: 4a52ab68ff6002ada59fd9357d5f478906c79e3220917538788bbeb8ed202475

Contents?: true

Size: 1.32 KB

Versions: 39

Compression:

Stored size: 1.32 KB

Contents

#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = GlobalFitDictList.rb -- Fit4Ruby - FIT file processing library for Ruby
#
# Copyright (c) 2014 by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

require 'fit4ruby/Log'

module Fit4Ruby

  class GlobalFitDict

    def initialize
      @entries = {}
    end

    def entry(number, name)
      if @entries.include?(number)
        Log.fatal "Entry #{number} has already been defined"
      end
      @entries[number] = name
    end

    def name(number)
      @entries[number]
    end

    def value_by_name(name)
      @entries.invert[name]
    end

  end

  class GlobalFitDictList

    def initialize(&block)
      @current_dict = nil
      @dicts = {}
      instance_eval(&block) if block_given?
    end

    def dict(name)
      if @dicts.include?(name)
        Log.fatal "Dictionary #{name} has already been defined"
      end
      @dicts[name] = @current_dict = GlobalFitDict.new
    end

    def entry(number, name)
      unless @current_dict
        Log.fatal "You must define a dictionary first"
      end
      @current_dict.entry(number, name)
    end

    def [](name)
      @dicts[name]
    end

  end

end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
fit4ruby-3.13.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.12.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.11.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.10.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.9.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.8.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.7.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.6.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.5.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.4.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.3.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.2.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.1.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-3.0.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-2.0.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-1.7.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-1.6.2 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-1.6.1 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-1.6.0 lib/fit4ruby/GlobalFitDictList.rb
fit4ruby-1.5.1 lib/fit4ruby/GlobalFitDictList.rb