lib/crate/raw.rb in data_crate-0.1.0 vs lib/crate/raw.rb in data_crate-0.1.1

- old
+ new

@@ -46,21 +46,32 @@ log_if_changed(raw, replaced) log_if_harmful(replaced) end end + def symbolize(object) + case object + when Hash + object.map { |key, value| [key.to_sym, symbolize(value)] }.to_h + else + object + end + end + + def make_hash(raw) + case raw + when String + JSON.parse(gsub(raw), symbolize_names: true) + when Hash + raw + else + raise + end + end + def initialize(raw, **options) @options = { logger: Logger.new(nil), severity: Logger::WARN, **options } - - @raw = - case raw - when String - JSON.parse(gsub(raw), symbolize_names: true) - when Hash - raw - else - raise - end + @raw = symbolize(make_hash(raw)) end def to_hash @raw end