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
-
.config ⇒ Hash
Outputs the configs of quotify-ruby.
-
.configure(opts = {}) ⇒ Object
Configure through hash.
-
.configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file.
-
.generate(quote: nil, author: nil) ⇒ Quotify::Quote
Generates a quote.
-
.reset_config ⇒ Object
Resets the configurations.
Class Method Details
.config ⇒ Hash
Outputs the configs of quotify-ruby
23 24 25 |
# File 'lib/quotify.rb', line 23 def self.config @config end |
.configure(opts = {}) ⇒ Object
Configure through hash
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
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
17 18 19 |
# File 'lib/quotify.rb', line 17 def self.generate(quote: nil, author: nil) Quote.new(quote: quote, author: ) end |
.reset_config ⇒ Object
Resets the configurations
50 51 52 |
# File 'lib/quotify.rb', line 50 def self.reset_config @config = @default_config.clone end |