From 21eddca873d2912e9f5f8ab88c681ce55cbe0c6f Mon Sep 17 00:00:00 2001 From: Chris Schlaeger Date: Sat, 12 Sep 2015 20:28:04 +0200 Subject: No need to split the add method into two separate methods. --- lib/postrunner/ActivitiesDB.rb | 19 +++++-------------- lib/postrunner/Main.rb | 3 +-- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb index 67e98c0..9264f55 100644 --- a/lib/postrunner/ActivitiesDB.rb +++ b/lib/postrunner/ActivitiesDB.rb @@ -85,13 +85,13 @@ module PostRunner end end - # Check if the fit file can be added. If it's already there or was deleted - # before, it's not welcome. + # Add a new FIT file to the database. # @param fit_file [String] Name of the FIT file. - # @return [TrueClass or FalseClass] True if the file can be added. False + # @return [TrueClass or FalseClass] True if the file could be added. False # otherwise. - def fit_file_welcome?(fit_file_name) + def add(fit_file_name, fit_activity) base_fit_file_name = File.basename(fit_file_name) + if @activities.find { |a| a.fit_file == base_fit_file_name } Log.debug "Activity #{fit_file_name} is already included in the archive" return false @@ -102,22 +102,13 @@ module PostRunner return false end - true - end - - # Add a new FIT file to the database. - # @param fit_file [String] Name of the FIT file. - # @return [TrueClass or FalseClass] True if the file could be added. False - # otherwise. - def add(fit_file_name, fit_activity) begin FileUtils.cp(fit_file_name, @fit_dir) rescue StandardError Log.fatal "Cannot copy #{fit_file_name} into #{@fit_dir}: #{$!}" end - @activities << (activity = Activity.new(self, - File.basename(fit_file_name), + @activities << (activity = Activity.new(self, base_fit_file_name, fit_activity)) @activities.sort! do |a1, a2| a2.timestamp <=> a1.timestamp diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb index f72d3f5..17ffe71 100644 --- a/lib/postrunner/Main.rb +++ b/lib/postrunner/Main.rb @@ -330,8 +330,7 @@ EOT end if fit_entity.is_a?(Fit4Ruby::Activity) - return @activities.fit_file_welcome?(fit_file_name) && - @activities.add(fit_file_name, fit_entity) + return @activities.add(fit_file_name, fit_entity) elsif fit_entity.is_a?(Fit4Ruby::Monitoring_B) else Log.error "#{fit_file_name} is not a recognized FIT file" -- cgit v1.2.3