Class: Dino::Components::BaseComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/dino/components/base_component.rb

Direct Known Subclasses

Button, IrReceiver, Led, RgbLed, Sensor, Servo, Stepper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BaseComponent

Returns a new instance of BaseComponent.



7
8
9
10
11
12
13
14
# File 'lib/dino/components/base_component.rb', line 7

def initialize(options={})
  self.board = options[:board]
  self.pin = options[:pin] || options[:pins]
  self.pullup = options[:pullup]

  raise 'board and pin or pins are required for a component' if self.board.nil? || self.pin.nil?
  after_initialize(options)
end

Instance Attribute Details

#boardObject

Returns the value of attribute board.



4
5
6
# File 'lib/dino/components/base_component.rb', line 4

def board
  @board
end

#pinObject Also known as: pins

Returns the value of attribute pin.



4
5
6
# File 'lib/dino/components/base_component.rb', line 4

def pin
  @pin
end

#pullupObject

Returns the value of attribute pullup.



4
5
6
# File 'lib/dino/components/base_component.rb', line 4

def pullup
  @pullup
end

Instance Method Details

#after_initialize(options = {}) ⇒ Object

Note:

This method should be implemented in the BaseComponent subclass.

As BaseComponent does a lot of work for you with regarding to setting up, it is best not to override #initialize and instead define an #after_initialize method within your subclass.



23
# File 'lib/dino/components/base_component.rb', line 23

def after_initialize(options={}) ; end