Class: Lazylead::Memes
- Inherits:
-
Object
- Object
- Lazylead::Memes
- Defined in:
- lib/lazylead/task/accuracy/memes.rb
Overview
TODO:
#339/DEV Prepare the meme list and attach them to the github, section .docs/accuracy/memes As url they will be required for configuration of the each task.
Meme generator based on tickets accuracy. For each range of scores there might be several available memes to be chosen randomly. If no meme found for score, empty url should be provided.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#find(score) ⇒ Object
Detect meme url based on accuracy score.
-
#initialize(memes, log: Log.new) ⇒ Memes
constructor
A new instance of Memes.
-
#range ⇒ Object
Parse json-based memes configuration.
Constructor Details
Instance Method Details
#enabled? ⇒ Boolean
42 43 44 |
# File 'lib/lazylead/task/accuracy/memes.rb', line 42 def enabled? !@memes.nil? && !range.empty? end |
#find(score) ⇒ Object
Detect meme url based on accuracy score.
49 50 51 52 53 |
# File 'lib/lazylead/task/accuracy/memes.rb', line 49 def find(score) r = range.find { |m| score >= m[0] && score <= m[1] } return "" if r.nil? r.last.sample end |
#range ⇒ Object
Parse json-based memes configuration. Expected format is
"memes": {
"0-9.9": "https://meme.com?id=awful1.gif,https://meme.com?id=awful2.gif",
"70-89.9": "https://meme.com?id=nice.gif",
"90-100": "https://meme.com?id=wow.gif"
}
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lazylead/task/accuracy/memes.rb', line 62 def range @range ||= if @memes.nil? [] else rng = JSON.parse(@memes).to_h return [] if rng.empty? rng.map do |k, v| next unless k.include? "-" row = k.split("-").map(&:to_f) row << v.split(",") row end end end |