Class: Lm::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/lm/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Product



7
8
9
# File 'lib/lm/product.rb', line 7

def initialize(str)
  @str = str
end

Instance Attribute Details

#strObject (readonly)

Returns the value of attribute str.



5
6
7
# File 'lib/lm/product.rb', line 5

def str
  @str
end

Instance Method Details

#to_s(v = nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/lm/product.rb', line 17

def to_s(v = nil)
  joiner = ""

  joiner = " & " if v == :verilog || (v.is_a?(Hash) && v[:verilog])
  vars.map { |x| x.to_s(v) }.compact.join(joiner)
end

#varsObject



11
12
13
14
15
# File 'lib/lm/product.rb', line 11

def vars
  @str.split("").each_with_index.map do |x, i|
    Variable.new(x, i)
  end
end