Module: MiGA::Result::Source
- Included in:
- MiGA::Result
- Defined in:
- lib/miga/result/source.rb
Overview
Helper module including functions to access the source of results
Instance Method Summary collapse
-
#key ⇒ Object
Detect the result key assigned to this result.
-
#project ⇒ Object
Project containing the result.
-
#project_path ⇒ Object
Path to the project containing the result.
-
#relative_dir ⇒ Object
Path of the result containing the directory relative to the parent project.
-
#relative_path ⇒ Object
Path of the result’s JSON definition relative to the parent project.
-
#source ⇒ Object
Load and return the source (parent object) of a result.
Instance Method Details
#key ⇒ Object
Detect the result key assigned to this result
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/miga/result/source.rb', line 19 def key @key ||= if relative_dir == 'data/90.stats' && file_path(:metadata_index) :project_stats else MiGA::Result.RESULT_DIRS.find do |k, v| "data/#{v}" == relative_dir end.first end end |
#project ⇒ Object
Project containing the result
44 45 46 |
# File 'lib/miga/result/source.rb', line 44 def project @project ||= MiGA::Project.load(project_path) end |
#project_path ⇒ Object
Path to the project containing the result. In most cases this should be identical to project.path
, but this function is provided for safety, so the path referencing is identical to that of self.path
whenever they need to be compared.
53 54 55 |
# File 'lib/miga/result/source.rb', line 53 def project_path path[0..path.rindex('/data/') - 1] end |
#relative_dir ⇒ Object
Path of the result containing the directory relative to the parent project
32 33 34 |
# File 'lib/miga/result/source.rb', line 32 def relative_dir @relative_dir ||= dir.sub("#{project_path}/", '') end |
#relative_path ⇒ Object
Path of the result’s JSON definition relative to the parent project
38 39 40 |
# File 'lib/miga/result/source.rb', line 38 def relative_path @relative_path ||= path.sub("#{project_path}/", '') end |
#source ⇒ Object
Load and return the source (parent object) of a result
8 9 10 11 12 13 14 15 |
# File 'lib/miga/result/source.rb', line 8 def source @source ||= if MiGA::Project.RESULT_DIRS[key] project else project.dataset(File.basename(path, '.json')) end end |