quotify 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f8b5ba09213aaa7238a8fd474560a9161fa5d6f6cda18137ef930d9d150b466
4
- data.tar.gz: 321fa9889c476be3d53208e1d405db2f10df7d8639345dc728ef1744cbc32d30
3
+ metadata.gz: 947b696a1aadf9f898e7ab6024bee8553634995e2515821d3a84a5d0b9e7a8ca
4
+ data.tar.gz: ba7bed8d8578c3d68fa5ad0b7bc198b4d319d28c1a4176bb98eb9e721fd6cfae
5
5
  SHA512:
6
- metadata.gz: 6a820edc5b569fddb1ee22f5fb3897e05ef95f27db82af818e0684ba95440e332dd04e86b7499bffc83dd60eef2c5ac0353e85fdca5acdc5625488ad0b3565dc
7
- data.tar.gz: 6bc7e2d329df8156ca1c3f615ba77839c9fc1b4f298a75332207547b44599f4219962b259ce3d4af8c55efb040aefbe184b52a781ec64ce97b4ee209a58cb586
6
+ metadata.gz: c0ebbdcb57598bb013368885bbe0b2a2229f4e78edf47f3a4fa410df9221cc48c4a0c30f36a440d2ca24e2f19755c562a7ec4d0f6e03f15489ba25edcea29004
7
+ data.tar.gz: 11115de3813e56912a2a5d643230f3e240e00c72dccb0953ad0e3c7b2e6faa14828b7d33a9d77a278cf38bcb455e53461d8c412ff80a4f23f36dd09a15a6dfe8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## V0.2.0rc
2
+ Saves the quotes in memory to prevent too many IO operations. Added configs that can be updated at runtime. `quotes.yml` only works with symbols as keys. From now on, prioritize symbols over strings. A new field `updated_at` was added to `quotes.yml` to allow for updating quotes using gem command. This will be added in the future.
3
+
1
4
  ## V0.1.1
2
5
  Fixes documentations formatting. No additional features were added.
3
6
 
data/lib/quotify/quote.rb CHANGED
@@ -12,21 +12,20 @@ module Quotify
12
12
  # @param author [#to_s] A specified author
13
13
  # @return [Quote] quote with author
14
14
  def initialize(quote: nil, author: nil)
15
- quote_list = YAML.load_file(File.join(__dir__, 'quotes.yml')) unless quote && author
16
- @quote = quote || quote_list['quotes'].sample
17
- @author = author || quote_list['authors'].sample
15
+ @quote = quote || Quotify.config[:quotes].sample
16
+ @author = author || Quotify.config[:authors].sample
18
17
  end
19
18
 
20
19
  # Returns the quote and author in a string format
21
20
  # @option spacer [#to_s] Characters between quote and author
22
- def to_s(spacer: " - ")
21
+ def to_s(spacer: Quotify.config[:default_spacer])
23
22
  "#{@quote}#{spacer}#{@author}"
24
23
  end
25
24
 
26
25
 
27
26
  # Returns the quote and author in a string format
28
27
  # @option spacer [#to_s] Characters between quote and author
29
- def to_str(spacer: " - ")
28
+ def to_str(spacer: Quotify.config[:default_spacer])
30
29
  to_s(spacer: spacer)
31
30
  end
32
31
 
@@ -1,4 +1,6 @@
1
- authors:
1
+ :updated_at: 2018-01-08
2
+ :default_spacer: ' - '
3
+ :authors:
2
4
  - Ivanka Trump
3
5
  - Dog The Bounty Hunter
4
6
  - Master Yoda
@@ -27,7 +29,7 @@ authors:
27
29
  - Olga
28
30
  - Logan Paul
29
31
 
30
- quotes:
32
+ :quotes:
31
33
  - The ode lives upon the ideal, the epic upon the grandiose, the drama upon the real.
32
34
  - If we don't study the mistakes of the future we're doomed to repeat them for the
33
35
  first time.
data/lib/quotify.rb CHANGED
@@ -4,6 +4,12 @@ require 'quotify/quote'
4
4
  # This module generates quotes on demand. Welcome to the future.
5
5
  module Quotify
6
6
 
7
+ @default_config = YAML.load_file(File.join(__dir__, 'quotify/quotes.yml'))
8
+
9
+ @config = @default_config.clone
10
+
11
+ @valid_config_keys = @config.keys
12
+
7
13
  # Generates a quote
8
14
  # @param quote [#to_s] A specified quote
9
15
  # @param author [#to_s] A specified author
@@ -11,4 +17,37 @@ module Quotify
11
17
  def self.generate(quote: nil, author: nil)
12
18
  Quote.new(quote: quote, author: author)
13
19
  end
20
+
21
+ # Outputs the configs of quotify-ruby
22
+ # @return [Hash]
23
+ def self.config
24
+ @config
25
+ end
26
+
27
+ # Configure through hash
28
+ # @param opts [Hash] A Hash of configurations
29
+ def self.configure(opts = {})
30
+ opts.each do |k,v|
31
+ @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
32
+ end
33
+ end
34
+
35
+ # Configure through yaml file
36
+ # @param path_to_yaml_file [Path] Path of the configuration file
37
+ def self.configure_with(path_to_yaml_file)
38
+ begin
39
+ config = YAML.load_file(path_to_yaml_file)
40
+ rescue Errno::ENOENT
41
+ puts "YAML configuration file couldn't be found. Using defaults."; return
42
+ rescue Psych::SyntaxError
43
+ puts "YAML configuration file contains invalid syntax. Using defaults."; return
44
+ end
45
+
46
+ configure(config)
47
+ end
48
+
49
+ # Resets the configurations
50
+ def self.reset_config
51
+ @config = @default_config.clone
52
+ end
14
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Leger