class Emotion::Picker::EmotionPicker

Class for choosing an emotion

Public Class Methods

new() click to toggle source
# File lib/emotion/picker.rb, line 16
def initialize
  @emotions = load
end

Public Instance Methods

pick() click to toggle source

Picks a random emotion and returns it @return [Emotion]

# File lib/emotion/picker.rb, line 22
def pick
  rand = Random.new
  index = rand.rand(0...@emotions.length)
  @emotions[index]
end

Private Instance Methods

load() click to toggle source

Loads the emotions file into an internal array @return [Array]

# File lib/emotion/picker.rb, line 32
def load
  emotions = []
  parsed = YAML.load_file(EMOTIONS_FILE)

  parsed.each do |emotion|
    emote = Emotion.new(emotion['name'], emotion['description'])
    emotions.push(emote)
  end

  emotions
end