Class: Lm::SumOfProducts
- Inherits:
-
Object
- Object
- Lm::SumOfProducts
- Defined in:
- lib/lm/sum_of_products.rb
Instance Attribute Summary collapse
-
#arr ⇒ Object
readonly
Returns the value of attribute arr.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #implicants ⇒ Object
-
#initialize(arr = []) ⇒ SumOfProducts
constructor
A new instance of SumOfProducts.
- #insert(product) ⇒ Object
- #to_s(v = nil) ⇒ Object
Constructor Details
#initialize(arr = []) ⇒ SumOfProducts
Returns a new instance of SumOfProducts.
7 8 9 |
# File 'lib/lm/sum_of_products.rb', line 7 def initialize(arr = []) @arr = arr end |
Instance Attribute Details
#arr ⇒ Object (readonly)
Returns the value of attribute arr.
5 6 7 |
# File 'lib/lm/sum_of_products.rb', line 5 def arr @arr end |
Instance Method Details
#<<(value) ⇒ Object
11 12 13 |
# File 'lib/lm/sum_of_products.rb', line 11 def <<(value) insert(value) end |
#implicants ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lm/sum_of_products.rb', line 19 def implicants result = {} @arr.each do |x| result[x.str.to_i(2).to_s] = x.str end ImplicantChart.new(result, length: @arr.first.str.length) end |
#insert(product) ⇒ Object
15 16 17 |
# File 'lib/lm/sum_of_products.rb', line 15 def insert(product) @arr << product end |
#to_s(v = nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/lm/sum_of_products.rb', line 27 def to_s(v = nil) joiner = "+" joiner = " | " if v == :verilog || (v.is_a?(Hash) && v[:verilog]) @arr.map { |x| x.to_s(v) }.join(joiner) end |