Class: Plt::Signal

Inherits:
Object
  • Object
show all
Defined in:
lib/plt/signal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, typestr, color, *properties) ⇒ Signal

Returns a new instance of Signal.



6
7
8
9
10
11
12
13
# File 'lib/plt/signal.rb', line 6

def initialize(name, typestr, color, *properties)
  @name       = name
  @bit        = typestr == "bit"
  @color      = color.to_i
  @properties = properties
    .map { Property.parse(_1) }
    .reduce({}) { |acc, e| acc.merge(e) }
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



5
6
7
# File 'lib/plt/signal.rb', line 5

def color
  @color
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/plt/signal.rb', line 5

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



5
6
7
# File 'lib/plt/signal.rb', line 5

def properties
  @properties
end

Class Method Details

.from_line(line) ⇒ Object



17
18
19
20
21
# File 'lib/plt/signal.rb', line 17

def self.from_line(line)
  new(*line.chomp.split(/\s+/))
rescue
  raise ArgumentError, "Cannot parse line \"#{line}\""
end

Instance Method Details

#bit?Boolean

Returns:

  • (Boolean)


15
# File 'lib/plt/signal.rb', line 15

def bit? = @bit

#to_plt(enabled = true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/plt/signal.rb', line 27

def to_plt(enabled=true)
  [
    (enabled ? nil : "~"),
    name,
    "",
    (bit? ? "bit" : "nobit"),
    color,
    *properties.map { |k, v| Property.to_plt(k, v) }
  ].compact.join(" ")
end

#to_sObject



23
24
25
# File 'lib/plt/signal.rb', line 23

def to_s
  name + (bit? ? " (bit)" : "")
end