Class: Plt::Signal
- Inherits:
-
Object
- Object
- Plt::Signal
- Defined in:
- lib/plt/signal.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #bit? ⇒ Boolean
-
#initialize(name, typestr, color, *properties) ⇒ Signal
constructor
A new instance of Signal.
- #to_plt(enabled = true) ⇒ Object
- #to_s ⇒ Object
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
#color ⇒ Object (readonly)
Returns the value of attribute color.
5 6 7 |
# File 'lib/plt/signal.rb', line 5 def color @color end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/plt/signal.rb', line 5 def name @name end |
#properties ⇒ Object (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
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_s ⇒ Object
23 24 25 |
# File 'lib/plt/signal.rb', line 23 def to_s name + (bit? ? " (bit)" : "") end |