Module: Quotify

Defined in:
lib/quotify.rb,
lib/quotify/quote.rb

Overview

This module generates quotes on demand. Welcome to the future.

Defined Under Namespace

Classes: Quote

Class Method Summary collapse

Class Method Details

.configHash

Outputs the configs of quotify-ruby

Returns:

  • (Hash)


23
24
25
# File 'lib/quotify.rb', line 23

def self.config
  @config
end

.configure(opts = {}) ⇒ Object

Configure through hash

Parameters:

  • opts (Hash) (defaults to: {})

    A Hash of configurations



29
30
31
32
33
# File 'lib/quotify.rb', line 29

def self.configure(opts = {})
  opts.each do |k,v|
    @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
  end
end

.configure_with(path_to_yaml_file) ⇒ Object

Configure through yaml file

Parameters:

  • path_to_yaml_file (Path)

    Path of the configuration file



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/quotify.rb', line 37

def self.configure_with(path_to_yaml_file)
  begin
    config = YAML.load_file(path_to_yaml_file)
  rescue Errno::ENOENT
    puts "YAML configuration file couldn't be found. Using defaults."; return
  rescue Psych::SyntaxError
    puts "YAML configuration file contains invalid syntax. Using defaults."; return
  end

  configure(config)
end

.generate(quote: nil, author: nil) ⇒ Quotify::Quote

Generates a quote

Parameters:

  • quote (#to_s) (defaults to: nil)

    A specified quote

  • author (#to_s) (defaults to: nil)

    A specified author

Returns:



17
18
19
# File 'lib/quotify.rb', line 17

def self.generate(quote: nil, author: nil)
  Quote.new(quote: quote, author: author)
end

.reset_configObject

Resets the configurations



50
51
52
# File 'lib/quotify.rb', line 50

def self.reset_config
  @config = @default_config.clone
end