quotify 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/quotify/quote.rb +4 -5
- data/lib/quotify/quotes.yml +4 -2
- data/lib/quotify.rb +39 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 947b696a1aadf9f898e7ab6024bee8553634995e2515821d3a84a5d0b9e7a8ca
|
4
|
+
data.tar.gz: ba7bed8d8578c3d68fa5ad0b7bc198b4d319d28c1a4176bb98eb9e721fd6cfae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
16
|
-
@
|
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
|
|
data/lib/quotify/quotes.yml
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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
|