Class: ConditionalMessages::FindMessage
- Inherits:
-
Object
- Object
- ConditionalMessages::FindMessage
- Defined in:
- lib/conditional_messages/find_message.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#context_holder ⇒ Object
readonly
Returns the value of attribute context_holder.
Class Method Summary collapse
Instance Method Summary collapse
- #find_message ⇒ Object
-
#initialize(context_holder, category) ⇒ FindMessage
constructor
A new instance of FindMessage.
Constructor Details
#initialize(context_holder, category) ⇒ FindMessage
Returns a new instance of FindMessage.
10 11 12 13 |
# File 'lib/conditional_messages/find_message.rb', line 10 def initialize(context_holder, category) @context_holder = context_holder @category = category end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
8 9 10 |
# File 'lib/conditional_messages/find_message.rb', line 8 def category @category end |
#context_holder ⇒ Object (readonly)
Returns the value of attribute context_holder.
8 9 10 |
# File 'lib/conditional_messages/find_message.rb', line 8 def context_holder @context_holder end |
Class Method Details
.for(*args) ⇒ Object
4 5 6 |
# File 'lib/conditional_messages/find_message.rb', line 4 def self.for(*args) new(*args). end |
Instance Method Details
#find_message ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/conditional_messages/find_message.rb', line 15 def = category.apply(context_holder) = .select(&:all_required_rules_pass?) by_score = .group_by(&:score) winners = by_score.sort_by { |score, | score }.last.last winners.sample end |