Module: Hashie::Extensions::KeyReplace
- Included in:
- ThetvdbApi::Base
- Defined in:
- lib/thetvdb_api/utility/hashie/extensions/key_replace.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/thetvdb_api/utility/hashie/extensions/key_replace.rb', line 4 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#initialize(source_hash = nil, default = nil, &blk) ⇒ Object
8 9 10 11 |
# File 'lib/thetvdb_api/utility/hashie/extensions/key_replace.rb', line 8 def initialize(source_hash = nil, default = nil, &blk) source_hash = replace_keys(source_hash) super end |
#replace_keys(source_hash) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/thetvdb_api/utility/hashie/extensions/key_replace.rb', line 13 def replace_keys(source_hash) source_hash.keys.each do |key| new_key = self.class.key_replace(key) || key.to_s.underscore if new_key != key source_hash[new_key] = source_hash[key] source_hash.delete(key) end end source_hash end |