Class: ParsableHash::Strategies
- Inherits:
-
Object
- Object
- ParsableHash::Strategies
- Defined in:
- lib/parsable_hash/strategies.rb
Class Attribute Summary collapse
Instance Method Summary collapse
- #[](strategy) ⇒ Object
- #[]=(strategy, value) ⇒ Object
- #add(strategy, value) ⇒ Object
- #get(strategy) ⇒ Object
-
#initialize(value = {}) ⇒ Strategies
constructor
A new instance of Strategies.
Constructor Details
#initialize(value = {}) ⇒ Strategies
Returns a new instance of Strategies.
13 14 15 |
# File 'lib/parsable_hash/strategies.rb', line 13 def initialize(value = {}) strategies[:default] = value end |
Class Attribute Details
.fallbacks ⇒ Object
6 7 8 |
# File 'lib/parsable_hash/strategies.rb', line 6 def fallbacks @fallbacks.nil? ? true : @fallbacks end |
Instance Method Details
#[](strategy) ⇒ Object
17 18 19 |
# File 'lib/parsable_hash/strategies.rb', line 17 def [](strategy) get(strategy) end |
#[]=(strategy, value) ⇒ Object
21 22 23 |
# File 'lib/parsable_hash/strategies.rb', line 21 def []=(strategy, value) add(strategy, value) end |
#add(strategy, value) ⇒ Object
34 35 36 |
# File 'lib/parsable_hash/strategies.rb', line 34 def add(strategy, value) strategies[strategy] = value end |
#get(strategy) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/parsable_hash/strategies.rb', line 25 def get(strategy) _strategy = strategies[strategy.to_sym] return _strategy unless _strategy.nil? return strategies[:default] if _strategy.nil? && self.class.fallbacks raise MissingStrategy.new("Strategy #{strategy} is missing!") end |