Class: Eletro::Transistor

Inherits:
Part
  • Object
show all
Defined in:
lib/eletro/transistor.rb

Instance Attribute Summary collapse

Attributes inherited from Part

#p0, #p1, #unit, #v, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Part

#*, #+, #-, #/, #abs, #coerce, #method_missing, #round, #to_f, #to_i, #to_s

Constructor Details

#initialize(*args) ⇒ Transistor

Returns a new instance of Transistor.



8
9
10
11
12
# File 'lib/eletro/transistor.rb', line 8

def initialize *args
  params, txt = *args.partition { |a| a.is_a?(Hash) }
  @npn = params[0] && params[0][:type] == "pnp" ? false : true
  @name = txt.join
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Eletro::Part

Instance Attribute Details

#hfeObject

Returns the value of attribute hfe.



6
7
8
# File 'lib/eletro/transistor.rb', line 6

def hfe
  @hfe
end

#iObject

Returns the value of attribute i.



6
7
8
# File 'lib/eletro/transistor.rb', line 6

def i
  @i
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/eletro/transistor.rb', line 6

def name
  @name
end

#riObject

Returns the value of attribute ri.



6
7
8
# File 'lib/eletro/transistor.rb', line 6

def ri
  @ri
end

Class Method Details

.npnObject



31
32
33
# File 'lib/eletro/transistor.rb', line 31

def self.npn
  new
end

.pnpObject



27
28
29
# File 'lib/eletro/transistor.rb', line 27

def self.pnp
  new(:type => "pnp")
end

Instance Method Details

#npn?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/eletro/transistor.rb', line 18

def npn?
  @npn
end

#pnp?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/eletro/transistor.rb', line 22

def pnp?
  !@npn
end

#wObject



14
15
16
# File 'lib/eletro/transistor.rb', line 14

def w
  v * i
end