Class: Pione::Package::ScenarioHandler
- Inherits:
-
Object
- Object
- Pione::Package::ScenarioHandler
- Includes:
- SimpleIdentity
- Defined in:
- lib/pione/package/scenario-handler.rb
Overview
ScenarioHandler handles scenario related operations.
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
-
#initialize(location, info) ⇒ ScenarioHandler
constructor
A new instance of ScenarioHandler.
-
#input ⇒ BasicLocation
Return input location of the scenario.
-
#inputs ⇒ BasicLocation
Return list of input data location.
-
#output ⇒ BasicLocation
Return the output location.
-
#outputs ⇒ BasicLocation
Return output file locations.
-
#validate(result_location) ⇒ Object
Validate reheasal results.
-
#write_info_file(option = {}) ⇒ Object
Write an information file for the scenario.
Constructor Details
#initialize(location, info) ⇒ ScenarioHandler
Returns a new instance of ScenarioHandler.
14 15 16 17 |
# File 'lib/pione/package/scenario-handler.rb', line 14 def initialize(location, info) @location = location @info = info end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
8 9 10 |
# File 'lib/pione/package/scenario-handler.rb', line 8 def info @info end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
7 8 9 |
# File 'lib/pione/package/scenario-handler.rb', line 7 def location @location end |
Instance Method Details
#input ⇒ BasicLocation
Return input location of the scenario. If the scenario doesn't have input location, return nil.
36 37 38 39 |
# File 'lib/pione/package/scenario-handler.rb', line 36 def input input_location = @location + "input" return input_location.exist? ? input_location : nil end |
#inputs ⇒ BasicLocation
Return list of input data location.
45 46 47 |
# File 'lib/pione/package/scenario-handler.rb', line 45 def inputs info.inputs.map {|path| @location + path} end |
#output ⇒ BasicLocation
Return the output location.
53 54 55 |
# File 'lib/pione/package/scenario-handler.rb', line 53 def output @location + "output" end |
#outputs ⇒ BasicLocation
Return output file locations.
61 62 63 |
# File 'lib/pione/package/scenario-handler.rb', line 61 def outputs @info.outputs.map {|path| @location + path} end |
#validate(result_location) ⇒ Object
Validate reheasal results.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pione/package/scenario-handler.rb', line 66 def validate(result_location) return [] unless output.exist? errors = [] output.entries.each do |entry| name = entry.basename result = result_location + name if result.exist? if entry.read != result.read errors << RehearsalResult.new(:different, name) end else errors << RehearsalResult.new(:not_exist, name) end end return errors end |
#write_info_file(option = {}) ⇒ Object
Write an information file for the scenario.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pione/package/scenario-handler.rb', line 20 def write_info_file(option={}) last_time = Util::LastTime.get(@info.filepaths.map{|path| @location + path}) # update the scenario info file location = @location + "pione-scenario.json" if option[:force] or not(location.exist?) or last_time > location.mtime location.write(JSON.pretty_generate(@info)) Log::SystemLog.info("update the scenario info file: %s" % location.address) end end |