Class: Array
Instance Method Summary collapse
- #accumulate ⇒ Object
- #collect_as_hash ⇒ Object
- #extract_options! ⇒ Object
- #hash_collection? ⇒ Boolean
- #hashify_or_collect ⇒ Object
Instance Method Details
#accumulate ⇒ Object
14 15 16 |
# File 'lib/socializer/scraper/extensions.rb', line 14 def accumulate flatten.compact.uniq end |
#collect_as_hash ⇒ Object
7 8 9 10 11 12 |
# File 'lib/socializer/scraper/extensions.rb', line 7 def collect_as_hash raise StandardError, "Array is not a hash collection!" unless hash_collection? flatten.compact.each_with_object(Hash.new([])) do |h1,h| h1.each{|k,v| h[k] = (h[k] | [v]).accumulate } end end |
#extract_options! ⇒ Object
22 23 24 |
# File 'lib/socializer/scraper/extensions.rb', line 22 def last.is_a?(Hash) && last.instance_of?(Hash) ? pop : {} end |
#hash_collection? ⇒ Boolean
3 4 5 |
# File 'lib/socializer/scraper/extensions.rb', line 3 def hash_collection? flatten.compact.reject{|v| v.is_a?(Hash)}.empty? end |
#hashify_or_collect ⇒ Object
18 19 20 |
# File 'lib/socializer/scraper/extensions.rb', line 18 def hashify_or_collect hash_collection? ? collect_as_hash : accumulate end |