Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/twitter/core_ext/hash.rb
Instance Method Summary collapse
-
#deep_merge(hash) ⇒ Hash
Merges self with another hash, recursively.
-
#merge_list!(list_id_or_screen_name) ⇒ Hash
Take a single list ID or slug and merge it into self with the correct key.
-
#merge_owner!(owner_id_or_owner_screen_name) ⇒ Hash
Take a single owner ID or owner screen name and merge it into self with the correct key (for Twitter API endpoints that want :owner_id and :owner_screen_name).
-
#merge_user!(user_id_or_screen_name) ⇒ Hash
Take a single user ID or screen name and merge it into self with the correct key.
-
#merge_users!(user_ids_or_screen_names) ⇒ Hash
Take a multiple user IDs and screen names and merge them into self with the correct keys.
Instance Method Details
#deep_merge(hash) ⇒ Hash
Merges self with another hash, recursively
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/twitter/core_ext/hash.rb', line 7 def deep_merge(hash) target = self.dup hash.keys.each do |key| if hash[key].is_a?(Hash) && self[key].is_a?(Hash) target[key] = target[key].deep_merge(hash[key]) next end target[key] = hash[key] end target end |
#merge_list!(list_id_or_screen_name) ⇒ Hash
Take a single list ID or slug and merge it into self with the correct key
71 72 73 74 75 76 77 78 79 |
# File 'lib/twitter/core_ext/hash.rb', line 71 def merge_list!(list_id_or_screen_name) case list_id_or_screen_name when Integer self[:list_id] = list_id_or_screen_name when String self[:slug] = list_id_or_screen_name end self end |
#merge_owner!(owner_id_or_owner_screen_name) ⇒ Hash
Take a single owner ID or owner screen name and merge it into self with the correct key (for Twitter API endpoints that want :owner_id and :owner_screen_name)
57 58 59 60 61 62 63 64 65 |
# File 'lib/twitter/core_ext/hash.rb', line 57 def merge_owner!(owner_id_or_owner_screen_name) case owner_id_or_owner_screen_name when Integer self[:owner_id] = owner_id_or_owner_screen_name when String self[:owner_screen_name] = owner_id_or_owner_screen_name end self end |
#merge_user!(user_id_or_screen_name) ⇒ Hash
Take a single user ID or screen name and merge it into self with the correct key
23 24 25 26 27 28 29 30 31 |
# File 'lib/twitter/core_ext/hash.rb', line 23 def merge_user!(user_id_or_screen_name) case user_id_or_screen_name when Integer self[:user_id] = user_id_or_screen_name when String self[:screen_name] = user_id_or_screen_name end self end |
#merge_users!(user_ids_or_screen_names) ⇒ Hash
Take a multiple user IDs and screen names and merge them into self with the correct keys
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/twitter/core_ext/hash.rb', line 37 def merge_users!(user_ids_or_screen_names) user_ids, screen_names = [], [] user_ids_or_screen_names.flatten.each do |user_id_or_screen_name| case user_id_or_screen_name when Integer user_ids << user_id_or_screen_name when String screen_names << user_id_or_screen_name end end self[:user_id] = user_ids.join(',') unless user_ids.empty? self[:screen_name] = screen_names.join(',') unless screen_names.empty? self end |