Class: Pony::Breeds::ReadPonyData

Inherits:
Object
  • Object
show all
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

Class Method Details

.get_pony_by_key(key) ⇒ Hash

Get data related to a pony by JSON key

Parameters:

  • key (Symbol) —

    the symbolized key used to retrieve data for a specific pony

Returns:

  • (Hash) —

    the hash containing the data for the pony



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

Parameters:

  • name (String) —

    the actual name of the pony

Returns:

  • (Hash) —

    the hash containing the data for 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

Returns:

  • (Hash) —

    the hash containing the data for the pony



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