Sha256: e249a16685b460b2015ed2876d45d37f1b50a1c246411033efccddd45658bb7e

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

module Talks
  class << self

    VOICES = %w(
      agnes albert alex bad bahh bells boing bruce bubbles cellos
      deranged fred good hysterical junior kathy pipe princess ralph
      trinoids vicki victoria whisper zarvox
    )

    PREFS = {
      info: 'vicki',
      warn: 'whisper',
      success: 'vicki',
      error: 'bad'
    }

    def voice
      @voice ||= :info
    end

    def voice=(voice = :info)
      @voice ||= voice
    end

    def voices
      VOICES
    end

    def say(message, options = {})
      type = options[:type].to_sym if options[:type]
      say_voice = \
        if options[:voice] and VOICES.include?(options[:voice].to_s)
          options[:voice]
        elsif PREFS.keys.include? type
          PREFS[type]
        else
          PREFS[voice]
        end
      `say -v #{say_voice} #{message}`
    end

    PREFS.keys.each do |type|
      define_method type do |message, options = {type: type}|
        say(message, options)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
talks-0.0.3 lib/talks.rb