Class: Hardware

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/hardware.rb

Overview

The Hardware model handles hardware related informations for the nearspeak tag.

Instance Method Summary (collapse)

Instance Method Details

- (Object) current_location

Output the current location of the tag.



19
20
21
# File 'app/models/hardware.rb', line 19

def current_location
  self.hardware_locations.last
end

- (Object) format_hardware

Format the hardware identifier into a valid format.



25
26
27
28
29
30
# File 'app/models/hardware.rb', line 25

def format_hardware
  # format iBeacon hardware
  if hardware_type.eql? HardwaresHelper::TYPE_BLE
    self.identifier = format_uuid(self.identifier)
  end
end

- (Object) validate_ble_hardware

Validate bluetooth le hardware.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/hardware.rb', line 50

def validate_ble_hardware
  # validate iBeacon hardware
  if hardware_type.eql? HardwaresHelper::TYPE_BLE
    unless is_valid_uuid(self.identifier)
      return errors.add(:identifier, I18n.t('hardware_validate_identifier_invalid'))
    end

    if self.major.blank?
      return errors.add(:major, I18n.t('hardware_validate_major_required'))
    end

    if self.minor.blank?
      return errors.add(:minor, I18n.t('hardware_validate_minor_required'))
    end
  end
end

- (Object) validate_hardware

Validate the hardare



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/hardware.rb', line 34

def validate_hardware
  # check if hardware is already setup in the system
  hw = Hardware.where(:identifier => self.identifier, :major => self.major, :minor => self.minor, :hardware_type => self.hardware_type)

  unless hw.blank?
    return errors.add(:identifier, I18n.t('hardware_validate_exists'))
  end

  # validate iBeacon hardware
  if hardware_type.eql? HardwaresHelper::TYPE_BLE
    validate_ble_hardware
  end
end