Class: Lm::Variable
- Inherits:
-
Object
- Object
- Lm::Variable
- Defined in:
- lib/lm/variable.rb
Constant Summary collapse
- LETTERS =
%(ABCDEFGHJKLMNPQRSTUVWXYZ)
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #bar ⇒ Object
-
#initialize(value, pos) ⇒ Variable
constructor
A new instance of Variable.
- #invalid? ⇒ Boolean
- #notop ⇒ Object
- #subscript ⇒ Object
- #to_abc(letters = LETTERS) ⇒ Object
- #to_s(input = nil) ⇒ Object
- #to_verilog(letter) ⇒ Object
- #to_x(input = "X") ⇒ Object
Constructor Details
#initialize(value, pos) ⇒ Variable
Returns a new instance of Variable.
7 8 9 10 |
# File 'lib/lm/variable.rb', line 7 def initialize(value, pos) @value = value @pos = pos end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/lm/variable.rb', line 5 def value @value end |
Instance Method Details
#bar ⇒ Object
20 21 22 |
# File 'lib/lm/variable.rb', line 20 def @value == "0" ? "\u0305" : "" end |
#invalid? ⇒ Boolean
12 13 14 |
# File 'lib/lm/variable.rb', line 12 def invalid? @value != "1" && @value != "0" end |
#notop ⇒ Object
16 17 18 |
# File 'lib/lm/variable.rb', line 16 def notop @value == "0" ? "~" : "" end |
#subscript ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/lm/variable.rb', line 24 def subscript result = "" @pos.to_s.split("").each do |digit| result += (0x2080 + digit.to_i).chr("UTF-8") end result end |
#to_abc(letters = LETTERS) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/lm/variable.rb', line 36 def to_abc(letters = LETTERS) return to_x if @pos >= letters.length return "" if invalid? letters[@pos] + end |
#to_s(input = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lm/variable.rb', line 55 def to_s(input = nil) input ||= LETTERS if input.is_a?(String) && input.end_with?("#") to_x(input[0]) elsif input == :verilog to_verilog(x) elsif input.is_a?(Hash) && input[:verilog] to_verilog(input[:verilog]) else to_abc(input) end end |
#to_verilog(letter) ⇒ Object
49 50 51 52 53 |
# File 'lib/lm/variable.rb', line 49 def to_verilog(letter) return nil if invalid? "#{notop}#{letter}[#{@pos}]" end |
#to_x(input = "X") ⇒ Object
43 44 45 46 47 |
# File 'lib/lm/variable.rb', line 43 def to_x(input = "X") return "" if invalid? input.to_s + + subscript end |