Skip to content

Commit

Permalink
Add run method to Pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
dessy committed Nov 4, 2014
1 parent 00733d8 commit 9d36b55
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions pedometer/models/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@

class Pipeline

attr_reader :user, :trial, :parser, :processor, :analyzer
attr_reader :file_path, :user, :trial, :parser, :processor, :analyzer

def self.run(upload)
pipeline = Pipeline.new(upload)
pipeline.feed
pipeline
end

def initialize(upload)
@file_path = upload.file_path
@user = upload.user
@trial = upload.trial
@parser = Parser.run(File.read(upload.file_path))
end

def feed
@parser = Parser.run(File.read(@file_path))
@processor = Processor.run(@parser.parsed_data)
@analyzer = Analyzer.run(@processor.filtered_data, user, trial)
@analyzer = Analyzer.run(@processor.filtered_data, @user, @trial)
end

end
4 changes: 2 additions & 2 deletions pedometer/pedometer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
get '/uploads' do
@error = "A #{params[:error]} error has occurred." if params[:error]
@pipelines = Upload.all.inject([]) do |a, upload|
a << Pipeline.new(upload)
a << Pipeline.run(upload)
a
end

Expand All @@ -16,7 +16,7 @@

get '/upload/*' do |file_path|
upload = Upload.find(file_path)
@pipeline = Pipeline.new(upload)
@pipeline = Pipeline.run(upload)

erb :upload
end
Expand Down
4 changes: 2 additions & 2 deletions pedometer/test/unit/pipeline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PipelineTest < Test::Unit::TestCase
def test_new_combined_data
file_path = 'test/data/female-167-70_1-100-10-bagwalk.txt'
upload = Upload.find(file_path)
pipeline = Pipeline.new(upload)
pipeline = Pipeline.run(upload)

assert_equal upload.user, pipeline.user
assert_equal upload.trial, pipeline.trial
Expand All @@ -32,7 +32,7 @@ def test_new_combined_data
def test_new_separated_data
file_path = 'test/data/female-167-70_2-100-10-bagwalk.txt'
upload = Upload.find(file_path)
pipeline = Pipeline.new(upload)
pipeline = Pipeline.run(upload)

assert_equal upload.user, pipeline.user
assert_equal upload.trial, pipeline.trial
Expand Down

0 comments on commit 9d36b55

Please sign in to comment.