Class: SnippetFinderService
- Inherits:
-
Object
- Object
- SnippetFinderService
- Includes:
- RedisSnippets::Util
- Defined in:
- app/services/snippet_finder_service.rb
Constant Summary collapse
- SECTION_DELIMITER =
"[section]"
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(key:) ⇒ SnippetFinderService
constructor
A new instance of SnippetFinderService.
Methods included from RedisSnippets::Util
Constructor Details
#initialize(key:) ⇒ SnippetFinderService
Returns a new instance of SnippetFinderService.
6 7 8 |
# File 'app/services/snippet_finder_service.rb', line 6 def initialize(key:) @key = key end |
Class Method Details
.random_snippet(content) ⇒ Object
17 18 19 20 21 22 |
# File 'app/services/snippet_finder_service.rb', line 17 def random_snippet(content) return "" if content.blank? snippets = content.split("#{SECTION_DELIMITER}").map { |section| section.gsub(/^\n/, "") } snippets[rand(snippets.length)] end |
Instance Method Details
#call ⇒ Object
10 11 12 |
# File 'app/services/snippet_finder_service.rb', line 10 def call self.class.random_snippet(SnippetStoreService.send(snippet_key(@key))) end |