Class: Bathysphere::Parser
- Inherits:
-
Object
- Object
- Bathysphere::Parser
- Defined in:
- lib/bathysphere/parser.rb
Instance Method Summary collapse
- #fetch(option_name, *refinements) ⇒ Object
-
#initialize(file_path) ⇒ Parser
constructor
A new instance of Parser.
-
#using(refinements_store) ⇒ Object
Set a refinements store.
Constructor Details
#initialize(file_path) ⇒ Parser
9 10 11 12 |
# File 'lib/bathysphere/parser.rb', line 9 def initialize(file_path) @file = file_path.downcase @data = YAML.load_file(file) end |
Instance Method Details
#fetch(option_name, *refinements) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bathysphere/parser.rb', line 27 def fetch(option_name, *refinements) option_value = @data.fetch(option_name.to_s) do raise KeyError, "key not found #{option_name.to_s.inspect} in #{file}" end if option_value.kind_of?(Hash) fetch_recursively(option_value, *refinements) else option_value end end |
#using(refinements_store) ⇒ Object
Set a refinements store
When a refinements store is available, the #fetch method will attempt to retrieve the refinements by calling reader methods on the store instead of using additional refinement arguments.
Returns self (i.e. is a chainable method).
22 23 24 25 |
# File 'lib/bathysphere/parser.rb', line 22 def using(refinements_store) @refinements_store = refinements_store self end |