Class: Lm::OutputString

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

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ OutputString



5
6
7
8
9
10
11
# File 'lib/lm/output_string.rb', line 5

def initialize(str)
  @str = str

  return unless @str.length < 2

  @str = @str.rjust(2, "0")
end

Instance Method Details

#bitcountObject



13
14
15
# File 'lib/lm/output_string.rb', line 13

def bitcount
  [Math.log(@str.length, 2).ceil, 1].max
end

#sopObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lm/output_string.rb', line 17

def sop
  res = SumOfProducts.new
  @str.length.times do |x|
    bitbreak = x.to_s(2).rjust(bitcount, "0")
    next if @str[x] == "0"

    prod = Product.new(bitbreak)
    res << prod
  end

  res
end

#to_s(v = nil) ⇒ Object



30
31
32
# File 'lib/lm/output_string.rb', line 30

def to_s(v = nil)
  sop.to_s(v)
end