Module: BMT
- Defined in:
- lib/bmt.rb,
lib/bmt/item.rb,
lib/bmt/step.rb,
lib/bmt/methodology.rb
Defined Under Namespace
Classes: Item, Methodology, MethodologyNotFoundError, Step, VersionNotFoundError
Constant Summary collapse
- DATA_DIR =
Pathname.new(__dir__).join('data')
Class Method Summary collapse
- .current_version ⇒ Object
-
.find(key, version: current_version) ⇒ Object
returns a Methodology object given a key and a version.
-
.json_dir_names ⇒ Object
Get names of directories matching lib/data/<major>-<minor>/.
- .methodology_json(key, version: current_version) ⇒ Object
-
.methodology_keys(version: current_version) ⇒ Object
returns available methodology keys for a given version.
- .methodology_pathname(key, version: current_version) ⇒ Object
-
.versions ⇒ Object
Infer the available versions of the BMT from the names of the files in the repo.
Class Method Details
.current_version ⇒ Object
36 37 38 |
# File 'lib/bmt.rb', line 36 def current_version versions.first end |
.find(key, version: current_version) ⇒ Object
returns a Methodology object given a key and a version
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bmt.rb', line 21 def find(key, version: current_version) raise VersionNotFoundError unless versions.include?(version) raise MethodologyNotFoundError unless methodology_keys(version:).include?(key) @methodologies[version].nil? && @methodologies[version] = {} @methodologies[version][key] ||= Methodology.new( key:, version:, attributes: methodology_json(key, version:) ) @methodologies[version][key] end |
.json_dir_names ⇒ Object
Get names of directories matching lib/data/<major>-<minor>/
66 67 68 69 70 71 |
# File 'lib/bmt.rb', line 66 def json_dir_names DATA_DIR.entries .map(&:basename) .map(&:to_s) .grep(/^[0-9]+\.[0-9]/).sort end |
.methodology_json(key, version: current_version) ⇒ Object
57 58 59 |
# File 'lib/bmt.rb', line 57 def methodology_json(key, version: current_version) JSON.parse(methodology_pathname(key, version:).read) end |
.methodology_keys(version: current_version) ⇒ Object
returns available methodology keys for a given version
41 42 43 44 45 46 47 48 |
# File 'lib/bmt.rb', line 41 def methodology_keys(version: current_version) @methodology_keys[version] ||= DATA_DIR.join(version, 'methodologies').entries .map(&:basename) .map(&:to_s) .grep(/json/) .map { |filepath| File.basename(filepath, File.extname(filepath)) } end |
.methodology_pathname(key, version: current_version) ⇒ Object
61 62 63 |
# File 'lib/bmt.rb', line 61 def methodology_pathname(key, version: current_version) DATA_DIR.join(version, 'methodologies', "#{key}.json") end |
.versions ⇒ Object
Infer the available versions of the BMT from the names of the files in the repo. The returned list is in order with the current version first.
53 54 55 |
# File 'lib/bmt.rb', line 53 def versions @versions ||= json_dir_names.sort.reverse! end |