Class: Ecu::Signal
- Inherits:
-
Object
- Object
- Ecu::Signal
- Defined in:
- lib/ecu/signals/signal.rb,
lib/ecu/interfaces/lab/signal.rb
Constant Summary collapse
- DEFAULT_SIGNAL_SIZE =
32- DEFAULT_PERIOD =
10e-3
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#task ⇒ Object
Returns the value of attribute task.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #bandwidth ⇒ Object
- #basename ⇒ Object
- #grep(regexp) ⇒ Object
- #hash ⇒ Object
-
#initialize(name:, task: "Undefined", description: nil) ⇒ Signal
constructor
A new instance of Signal.
- #period ⇒ Object
- #to_h ⇒ Object
- #to_lab ⇒ Object
- #to_s ⇒ Object
- #with(hsh = {}) ⇒ Object
Constructor Details
#initialize(name:, task: "Undefined", description: nil) ⇒ Signal
Returns a new instance of Signal.
11 12 13 14 15 |
# File 'lib/ecu/signals/signal.rb', line 11 def initialize(name:, task: "Undefined", description: nil) @name = name.chomp.strip @task = task @description = description end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/ecu/signals/signal.rb', line 9 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/ecu/signals/signal.rb', line 9 def name @name end |
#task ⇒ Object
Returns the value of attribute task.
9 10 11 |
# File 'lib/ecu/signals/signal.rb', line 9 def task @task end |
Instance Method Details
#<=>(other) ⇒ Object
17 18 19 20 |
# File 'lib/ecu/signals/signal.rb', line 17 def <=>(other) return nil unless other.is_a?(self.class) name.downcase <=> other.name.downcase end |
#==(other) ⇒ Object Also known as: eql?
22 23 24 |
# File 'lib/ecu/signals/signal.rb', line 22 def ==(other) name == other.name end |
#bandwidth ⇒ Object
35 36 37 |
# File 'lib/ecu/signals/signal.rb', line 35 def bandwidth DEFAULT_SIGNAL_SIZE / period end |
#basename ⇒ Object
51 52 53 |
# File 'lib/ecu/signals/signal.rb', line 51 def basename name.sub(/_\[\d+\]$/, "") end |
#grep(regexp) ⇒ Object
31 32 33 |
# File 'lib/ecu/signals/signal.rb', line 31 def grep(regexp) name.match(regexp) || (!description.nil? && description.match(regexp)) end |
#hash ⇒ Object
27 28 29 |
# File 'lib/ecu/signals/signal.rb', line 27 def hash [name].hash end |
#period ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ecu/signals/signal.rb', line 39 def period return DEFAULT_PERIOD if task.nil? case task when /100us/ then 100e-6 when /10ms/ then 10e-3 when /segment/ then 12e-3 when /100ms/ then 100e-3 when /1s/ then 1 else DEFAULT_PERIOD end end |
#to_h ⇒ Object
55 56 57 58 59 |
# File 'lib/ecu/signals/signal.rb', line 55 def to_h instance_variables. map { |v| [v.to_s[1..-1].to_sym, instance_variable_get(v)] }. to_h end |
#to_lab ⇒ Object
3 4 5 |
# File 'lib/ecu/interfaces/lab/signal.rb', line 3 def to_lab "#{name};#{task};#{description}" end |
#to_s ⇒ Object
61 62 63 64 65 |
# File 'lib/ecu/signals/signal.rb', line 61 def to_s str = "Signal: #{name}" str << " [#{task}]" unless task.nil? str end |
#with(hsh = {}) ⇒ Object
67 68 69 70 |
# File 'lib/ecu/signals/signal.rb', line 67 def with(hsh={}) return self if hsh.empty? self.class.new(**to_h.merge(hsh)) end |