diff options
author | Chris Schlaeger <chris@linux.com> | 2014-11-17 03:11:53 +0100 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-11-17 03:11:53 +0100 |
commit | bdc7d05a19747b68d10eb0303c3472571aa3ce61 (patch) | |
tree | ab89ce84a3dfa0879740ea7428b88073ca537902 /lib | |
parent | 70fa9815704d2552d9f24e1051566ad7773fda48 (diff) | |
download | postrunner-bdc7d05a19747b68d10eb0303c3472571aa3ce61.zip |
New: Add 'set' option to change name, type and subtype of activities.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/ActivitiesDB.rb | 5 | ||||
-rw-r--r-- | lib/postrunner/Activity.rb | 25 | ||||
-rw-r--r-- | lib/postrunner/Main.rb | 22 |
3 files changed, 50 insertions, 2 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb index ea51dab..b66f6eb 100644 --- a/lib/postrunner/ActivitiesDB.rb +++ b/lib/postrunner/ActivitiesDB.rb @@ -138,6 +138,11 @@ module PostRunner sync end + def set(activity, attribute, value) + activity.set(attribute, value) + sync + end + def check @activities.each { |a| a.check } end diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb index b3b55d4..0328d22 100644 --- a/lib/postrunner/Activity.rb +++ b/lib/postrunner/Activity.rb @@ -71,7 +71,7 @@ module PostRunner 'lap_swimming' => 'Lap Swimming', 'open_water' => 'Open Water', 'flexibility_training' => 'Flexibility Training', - 'strength_training' => 'Strength Traiming', + 'strength_training' => 'Strength Training', 'warm_up' => 'Warm up', 'match' => 'Match', 'exercise' => 'Excersize', @@ -178,6 +178,29 @@ module PostRunner generate_html_view end + def set(attribute, value) + case attribute + when 'name' + @name = value + when 'type' + unless @@ActivityTypes.values.include?(value) + Log.fatal "Unknown activity type '#{value}'. Must be one of " + + @@ActivityTypes.values.join(', ') + end + @sport = @@ActivityTypes.invert[value] + when 'subtype' + unless @@ActivitySubTypes.values.include?(value) + Log.fatal "Unknown activity subtype '#{value}'. Must be one of " + + @@ActivitySubTypes.values.join(', ') + end + @sub_sport = @@ActivitySubTypes.invert[value] + else + Log.fatal "Unknown activity attribute '#{attribute}'. Must be one of " + + 'name, type or subtype' + end + generate_html_view + end + def register_records(db) @fit_activity.personal_records.each do |r| if r.longest_distance == 1 diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb index 32dc254..f368028 100644 --- a/lib/postrunner/Main.rb +++ b/lib/postrunner/Main.rb @@ -32,6 +32,8 @@ module PostRunner def initialize(args) @filter = nil @name = nil + @attribute = nil + @value = nil @activities = nil @db_dir = File.join(ENV['HOME'], '.postrunner') @@ -138,6 +140,14 @@ rename <new name> <ref> new name that describes the activity. By default the activity name matches the FIT file name. +set <attribute> <value> <ref> + For the specified activies set the attribute to the given value. The + following attributes are supported: + + name: The activity name (defaults to FIT file name) + type: The type of the activity + subtype: The subtype of the activity + show [ <ref> ] Show the referenced FIT activity in a web browser. If no reference is provided show the list of activities in the database. @@ -207,9 +217,17 @@ EOT @activities.show_records when 'rename' unless (@name = args.shift) - Log.fatal "You must provide a new name for the activity" + Log.fatal 'You must provide a new name for the activity' end process_activities(args, :rename) + when 'set' + unless (@attribute = args.shift) + Log.fatal 'You must specify the attribute you want to change' + end + unless (@value = args.shift) + Log.fatal 'You must specify the new value for the attribute' + end + process_activities(args, :set) when 'show' if args.empty? @activities.show_list_in_browser @@ -295,6 +313,8 @@ EOT activity.dump(@filter) when :rename @activities.rename(activity, @name) + when :set + @activities.set(activity, @attribute, @value) when :show activity.show when :summary |