Class: Lm::String122ResultSelector
- Inherits:
-
Object
- Object
- Lm::String122ResultSelector
- Defined in:
- lib/lm/string_122_result_selector.rb
Instance Method Summary collapse
- #chart ⇒ Object
-
#initialize(pm, sum) ⇒ String122ResultSelector
constructor
A new instance of String122ResultSelector.
- #shortest ⇒ Object
- #sum_list ⇒ Object
- #sum_strings ⇒ Object
Constructor Details
#initialize(pm, sum) ⇒ String122ResultSelector
Returns a new instance of String122ResultSelector.
5 6 7 8 |
# File 'lib/lm/string_122_result_selector.rb', line 5 def initialize(pm, sum) @pm = pm @sum = sum end |
Instance Method Details
#chart ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/lm/string_122_result_selector.rb', line 10 def chart @chart ||= @pm.soplist.map do |k, v| { columns: k, product: v } end end |
#shortest ⇒ Object
32 33 34 35 |
# File 'lib/lm/string_122_result_selector.rb', line 32 def shortest idx = sum_strings.min_by { |x| x[:str].length }[:idx] SumOfProducts.new(sum_list[idx]) end |
#sum_list ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/lm/string_122_result_selector.rb', line 19 def sum_list @sum.str.split("+").map do |term| term.split("").map do |str122| idx = str122.ord - 48 chart[idx][:product] end end end |
#sum_strings ⇒ Object
28 29 30 |
# File 'lib/lm/string_122_result_selector.rb', line 28 def sum_strings sum_list.each_with_index.map { |x, i| { str: x.join("+"), idx: i } } end |