Method: Astronomy::Information#search

Defined in:
lib/astronomy.rb

#search(topic) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/astronomy.rb', line 22

def search(topic)
  query = topic.downcase
  results = []

  @data.each do |category, array_of_topics|
    array_of_topics.each do |topic|
      results << topic and next if topic['name'].downcase.include?(query)
      results << topic if topic['description'].downcase.include?(query)
    end
  end

  results
end