How to retrieve all hash keys

Makjb lh

This is the hash value:

resource = RestClient::Resource.new 'http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=BMI'
puts response_Json = eval(resource.get)

I can't get get the values recursively for all 'Since' keys.

I tried many solutions on Stack Overflow including accepted answers and tried to modify them.

def extract_list(hash, find_By_Key, collect = false)
  if (hash.class == Array) then
          hash.each { |value| puts hash; extract_list(value, find_By_Key) }
  end
  hash.map do |k, v|
      puts k.class
v.is_a?(Hash) ? extract_list(v, find_By_Key, (k == find_By_Key)) :
    (collect ? v : nil)
v.is_a?(Array) ? extract_list(v, find_By_Key, (k == find_By_Key)) :
    (collect ? v : nil)
v.is_a?(Symbol) ?  (collect ? v : nil):
    (puts v)    
  end.compact.flatten
end
Damiano Stoffie

Hope this helps!

require 'rest-client'

def extract_list(data, key)
  if data.class == Array
    data.flat_map { |e|
      extract_list(e, key)
    }.compact
  elsif data.class == Hash
    data.flat_map { |k, v|
      if k == key
        v
      else
        extract_list(v, key)
      end
    }.compact
  end
end

resource = RestClient::Resource.new 'http://www.nactem.ac.uk/software/acromine/dictionary.py?sf=BMI'
data = JSON.parse(resource.get)
p extract_list(data, "since")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to retrieve data from all keys in Firebase?

From Dev

How to replace all hash keys having a '.'?

From Dev

How to make a particular change in all the keys of a hash?

From Dev

How to convert an array to a hash with array elements as hash keys and all hash values all set to given value

From Dev

How to convert an array to a hash with array elements as hash keys and all hash values all set to given value

From Dev

With jekyll / liquid how to get all keys of a yml hash

From Dev

How to retrieve all the columns from all of the tables in a particular database which are not part of primary keys and foreign keys

From Dev

How to retrieve all the columns from all of the tables in a particular database which are not part of primary keys and foreign keys

From Dev

How to change hash keys

From Dev

How to retrieve a GET variable with a hash in it

From Dev

How to retrieve multiple keys in Firebase?

From Dev

Table Storage: Retrieve all partition keys

From Dev

Retrieve all the keys in an array of objects with a particular value

From Dev

Get all keys from ruby hash

From Dev

Rails - Get all keys from params hash

From Dev

Perl get all keys in a hash that as defined values

From Dev

Better way to retrieve values from matching keys in a ruby hash

From Dev

Finding n keys that all hash to same hash value

From Dev

Using Joi/Hapi, how can one validate the entries in a hash, for all keys?

From Dev

Ruby: Get all keys in a hash (including sub keys)

From Java

How to retrieve values after a hash collision

From Java

How to retrieve the hash for the current commit in Git?

From Dev

How to retrieve hash value from session in Perl

From Dev

how to retrieve keys only when filter by value

From Dev

how to retrieve keys from a multidimensional array

From Dev

how to retrieve multiple keys in firebase with forloop?

From Java

How to get hash keys in order of their appearance

From Dev

How to sort a Ruby Hash alphabetically by keys

From Dev

How to initialize a hash with keys from an array?

Related Related

  1. 1

    How to retrieve data from all keys in Firebase?

  2. 2

    How to replace all hash keys having a '.'?

  3. 3

    How to make a particular change in all the keys of a hash?

  4. 4

    How to convert an array to a hash with array elements as hash keys and all hash values all set to given value

  5. 5

    How to convert an array to a hash with array elements as hash keys and all hash values all set to given value

  6. 6

    With jekyll / liquid how to get all keys of a yml hash

  7. 7

    How to retrieve all the columns from all of the tables in a particular database which are not part of primary keys and foreign keys

  8. 8

    How to retrieve all the columns from all of the tables in a particular database which are not part of primary keys and foreign keys

  9. 9

    How to change hash keys

  10. 10

    How to retrieve a GET variable with a hash in it

  11. 11

    How to retrieve multiple keys in Firebase?

  12. 12

    Table Storage: Retrieve all partition keys

  13. 13

    Retrieve all the keys in an array of objects with a particular value

  14. 14

    Get all keys from ruby hash

  15. 15

    Rails - Get all keys from params hash

  16. 16

    Perl get all keys in a hash that as defined values

  17. 17

    Better way to retrieve values from matching keys in a ruby hash

  18. 18

    Finding n keys that all hash to same hash value

  19. 19

    Using Joi/Hapi, how can one validate the entries in a hash, for all keys?

  20. 20

    Ruby: Get all keys in a hash (including sub keys)

  21. 21

    How to retrieve values after a hash collision

  22. 22

    How to retrieve the hash for the current commit in Git?

  23. 23

    How to retrieve hash value from session in Perl

  24. 24

    how to retrieve keys only when filter by value

  25. 25

    how to retrieve keys from a multidimensional array

  26. 26

    how to retrieve multiple keys in firebase with forloop?

  27. 27

    How to get hash keys in order of their appearance

  28. 28

    How to sort a Ruby Hash alphabetically by keys

  29. 29

    How to initialize a hash with keys from an array?

HotTag

Archive