diff options
author | Chris Schlaeger <chris@linux.com> | 2015-09-12 20:28:04 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2015-09-12 20:28:04 +0200 |
commit | 21eddca873d2912e9f5f8ab88c681ce55cbe0c6f (patch) | |
tree | e4d44de417008e82695ccf39675081b08a55413f | |
parent | ccc542fb3d2e339debef5ed5195217ab1f7232a4 (diff) | |
download | postrunner-21eddca873d2912e9f5f8ab88c681ce55cbe0c6f.zip |
No need to split the add method into two separate methods.
-rw-r--r-- | lib/postrunner/ActivitiesDB.rb | 19 | ||||
-rw-r--r-- | lib/postrunner/Main.rb | 3 |
2 files changed, 6 insertions, 16 deletions
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" |