Module: Html2rss::Config::Schema::DeepStringifier

Defined in:
lib/html2rss/config/schema.rb

Overview

Converts nested hash keys to strings so the resulting schema serializes cleanly.

Class Method Summary collapse

Class Method Details

.call(object) ⇒ Hash, ...

Returns deep copy with stringified hash keys.

Parameters:

  • object (Hash, Array, Object)

    nested data to normalize

Returns:

  • (Hash, Array, Object)

    deep copy with stringified hash keys



219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/html2rss/config/schema.rb', line 219

def call(object)
  case object
  when Hash
    stringify_hash(object)
  when Array
    object.map { |value| call(value) }
  when Symbol
    object.to_s
  else
    object
  end
end

.stringify_hash(object) ⇒ Hash{String => Object}

Returns hash with recursively normalized values.

Parameters:

  • object (Hash{Object => Object})

    hash whose keys should become strings

Returns:

  • (Hash{String => Object})

    hash with recursively normalized values



234
235
236
# File 'lib/html2rss/config/schema.rb', line 234

def stringify_hash(object)
  object.to_h { |key, value| [key.to_s, call(value)] }
end