Class: DaFace::Datasift::Links
- Inherits:
-
Array
- Object
- Array
- DaFace::Datasift::Links
- Defined in:
- lib/da_face/datasift/links.rb
Class Method Summary collapse
- .get_elements(data = {}) ⇒ Object
-
.get_values(index, keys, hash) ⇒ Object
Recursively search the hash for elements of index ‘index’ from the arrays inside the hashes.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Links
constructor
A new instance of Links.
Constructor Details
Class Method Details
.get_elements(data = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/da_face/datasift/links.rb', line 10 def self.get_elements data={} hashed_links = [] unless data.empty? data.values.first.size.times do |index| hashed_links << get_values(index - 1, data.keys, data) end end return hashed_links end |
.get_values(index, keys, hash) ⇒ Object
Recursively search the hash for elements of index ‘index’ from the arrays inside the hashes.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/da_face/datasift/links.rb', line 22 def self.get_values index, keys, hash new_hash = {} keys.each do |key| if hash[key].kind_of? Hash new_hash[key] = get_values(index, hash[key].keys, hash[key]) else new_hash[key] = hash[key][index] end end return new_hash end |