Class: Pony::Breeds::ReadPonyData
- Inherits:
-
Object
- Object
- Pony::Breeds::ReadPonyData
- Defined in:
- lib/pony/breeds/read_pony_data.rb
Overview
The ReadPonyData class provides a way to read the pony data from the stored json file
Class Method Summary collapse
-
.get_pony_by_key(key) ⇒ Hash
Get data related to a pony by JSON key.
-
.get_pony_by_name(name) ⇒ Hash
Get data related to a pony by the actual name of the pony.
-
.retrieve_random_pony ⇒ Hash
Get data related to a pony by a random JSON key.
Class Method Details
.get_pony_by_key(key) ⇒ Hash
Get data related to a pony by JSON key
15 16 17 |
# File 'lib/pony/breeds/read_pony_data.rb', line 15 def self.get_pony_by_key(key) read_ponies[key&.to_sym] end |
.get_pony_by_name(name) ⇒ Hash
Get data related to a pony by the actual name of the pony
24 25 26 27 28 29 |
# File 'lib/pony/breeds/read_pony_data.rb', line 24 def self.get_pony_by_name(name) return unless name.is_a?(String) && !name.empty? key = name.split.join('_').downcase get_pony_by_key(key) end |
.retrieve_random_pony ⇒ Hash
Get data related to a pony by a random JSON key
34 35 36 37 38 39 |
# File 'lib/pony/breeds/read_pony_data.rb', line 34 def self.retrieve_random_pony arr = [] read_ponies.each_key { |pony_name| arr << pony_name } get_pony_by_key(arr.sample) end |