summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-11-17 03:11:53 +0100
committerChris Schlaeger <chris@linux.com>2014-11-17 03:11:53 +0100
commitbdc7d05a19747b68d10eb0303c3472571aa3ce61 (patch)
treeab89ce84a3dfa0879740ea7428b88073ca537902
parent70fa9815704d2552d9f24e1051566ad7773fda48 (diff)
downloadpostrunner-bdc7d05a19747b68d10eb0303c3472571aa3ce61.zip
New: Add 'set' option to change name, type and subtype of activities.
-rw-r--r--lib/postrunner/ActivitiesDB.rb5
-rw-r--r--lib/postrunner/Activity.rb25
-rw-r--r--lib/postrunner/Main.rb22
-rw-r--r--spec/PostRunner_spec.rb33
4 files changed, 83 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
diff --git a/spec/PostRunner_spec.rb b/spec/PostRunner_spec.rb
index ac67c80..e146e3f 100644
--- a/spec/PostRunner_spec.rb
+++ b/spec/PostRunner_spec.rb
@@ -113,6 +113,39 @@ describe PostRunner::Main do
list.index('foobar').should be_a(Fixnum)
end
+ it 'should fail when setting bad attribute' do
+ lambda { postrunner(%w( set foo bar :1)) }.should raise_error SystemExit
+ end
+
+ it 'should set name for FILE2.FIT activity' do
+ postrunner(%w( set name foobar :1 ))
+ list = postrunner(%w( list ))
+ list.index('FILE2.FIT').should be_nil
+ list.index('foobar').should be_a(Fixnum)
+ end
+
+ it 'should set activity type for FILE2.FIT activity' do
+ postrunner(%w( set type Cycling :1 ))
+ list = postrunner(%w( summary :1 ))
+ list.index('Running').should be_nil
+ list.index('Cycling').should be_a(Fixnum)
+ end
+
+ it 'should fail when setting bad activity type' do
+ lambda { postrunner(%w( set type foobar :1)) }.should raise_error SystemExit
+ end
+
+ it 'should set activity subtype for FILE2.FIT activity' do
+ postrunner(%w( set subtype Road :1 ))
+ list = postrunner(%w( summary :1 ))
+ list.index('Generic').should be_nil
+ list.index('Road').should be_a(Fixnum)
+ end
+
+ it 'should fail when setting bad activity subtype' do
+ lambda { postrunner(%w( set subtype foobar :1)) }.should raise_error SystemExit
+ end
+
it 'should dump an activity from the archive' do
postrunner(%w( dump :1 ))
end