diff --git a/lib/fit4ruby/BDFieldNameTranslator.rb b/lib/fit4ruby/BDFieldNameTranslator.rb index 16a4947..9f4f8ed 100644 --- a/lib/fit4ruby/BDFieldNameTranslator.rb +++ b/lib/fit4ruby/BDFieldNameTranslator.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # -# = FitDataRecord.rb -- Fit4Ruby - FIT file processing library for Ruby +# = BDFieldNameTranslator.rb -- Fit4Ruby - FIT file processing library for Ruby # # Copyright (c) 2020 by Chris Schlaeger # @@ -23,11 +23,7 @@ module BDFieldNameTranslator } def to_bd_field_name(name) - if (bd_name = BD_DICT[name]) - return bd_name - end - - name + BD_DICT.fetch(name, name) end end diff --git a/spec/BDFieldNameTranslator_spec.rb b/spec/BDFieldNameTranslator_spec.rb new file mode 100644 index 0000000..14160df --- /dev/null +++ b/spec/BDFieldNameTranslator_spec.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby -w +# encoding: UTF-8 +# +# = BDFieldNameTranslator_spec.rb -- Fit4Ruby - FIT file processing library for Ruby +# +# Copyright (c) 2014, 2015 by Chris Schlaeger +# +# 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. +# + +$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) + +require 'fit4ruby/BDFieldNameTranslator' + +describe Fit4Ruby::BDFieldNameTranslator do + + include described_class + + it 'should translate "array" to "_array"' do + expect(to_bd_field_name('array')).to eq('_array') + end + + it 'should translate "type" to "_type"' do + expect(to_bd_field_name('type')).to eq('_type') + end + + it 'should NOT translate "blegga"' do + expect(to_bd_field_name('blegga')).to eq('blegga') + end + +end +