Class: Lookbook::DataParser
- Defined in:
- lib/lookbook/services/data/parsers/data_parser.rb
Direct Known Subclasses
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(input, fail_silently: false, fallback: nil) ⇒ DataParser
constructor
A new instance of DataParser.
Methods inherited from Service
Constructor Details
#initialize(input, fail_silently: false, fallback: nil) ⇒ DataParser
Returns a new instance of DataParser.
3 4 5 6 7 |
# File 'lib/lookbook/services/data/parsers/data_parser.rb', line 3 def initialize(input, fail_silently: false, fallback: nil) @input = input @fail_silently = fail_silently @fallback = fallback end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 |
# File 'lib/lookbook/services/data/parsers/data_parser.rb', line 9 def call result = @input.present? ? parse(@input) : @fallback result.is_a?(Hash) ? result.deep_symbolize_keys : result rescue => exception @fail_silently ? @fallback : raise(exception) end |