Class: Astronomy::Information
- Inherits:
-
Object
- Object
- Astronomy::Information
- Defined in:
- lib/astronomy.rb
Constant Summary collapse
- DATA_FILE =
File.join(File.dirname(__dir__), 'assets', 'astronomy.yml')
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #categories ⇒ Object
-
#initialize ⇒ Information
constructor
A new instance of Information.
- #search(topic) ⇒ Object
- #topics(category) ⇒ Object
Constructor Details
#initialize ⇒ Information
Returns a new instance of Information.
10 11 12 |
# File 'lib/astronomy.rb', line 10 def initialize @data = YAML.load_file(DATA_FILE) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/astronomy.rb', line 8 def data @data end |
Instance Method Details
#categories ⇒ Object
14 15 16 |
# File 'lib/astronomy.rb', line 14 def categories @data.keys end |
#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 |
#topics(category) ⇒ Object
18 19 20 |
# File 'lib/astronomy.rb', line 18 def topics(category) @data[category] end |