Class: Device::Magnetic
- Inherits:
-
Object
- Object
- Device::Magnetic
- Defined in:
- lib/device/magnetic.rb
Constant Summary collapse
- HARDWARE_RET_OK =
0
- HARDWARE_SUCCESSFUL_READ =
1
- HARDWARE_NOT_READ =
0
- STATUS_SUCCESSFUL_READ =
:success
- STATUS_READ_TRACKS =
:read
- STATUS_CLOSE =
:close
- STATUS_OPEN =
:open
- STATUS_OPEN_FAIL =
:open_fail
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#track1 ⇒ Object
readonly
Returns the value of attribute track1.
-
#track2 ⇒ Object
readonly
Returns the value of attribute track2.
-
#track3 ⇒ Object
readonly
Returns the value of attribute track3.
-
#tracks ⇒ Object
readonly
Returns the value of attribute tracks.
Class Method Summary collapse
Instance Method Summary collapse
- #adapter ⇒ Object
- #bin?(value) ⇒ Boolean
- #close ⇒ Object
-
#initialize ⇒ Magnetic
constructor
A new instance of Magnetic.
- #open? ⇒ Boolean
- #read ⇒ Object
- #read? ⇒ Boolean
- #start ⇒ Object
- #swiped? ⇒ Boolean
Constructor Details
#initialize ⇒ Magnetic
Returns a new instance of Magnetic.
33 34 35 36 |
# File 'lib/device/magnetic.rb', line 33 def initialize @status = STATUS_CLOSE @open = self.start end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
31 32 33 |
# File 'lib/device/magnetic.rb', line 31 def status @status end |
#track1 ⇒ Object (readonly)
Returns the value of attribute track1.
31 32 33 |
# File 'lib/device/magnetic.rb', line 31 def track1 @track1 end |
#track2 ⇒ Object (readonly)
Returns the value of attribute track2.
31 32 33 |
# File 'lib/device/magnetic.rb', line 31 def track2 @track2 end |
#track3 ⇒ Object (readonly)
Returns the value of attribute track3.
31 32 33 |
# File 'lib/device/magnetic.rb', line 31 def track3 @track3 end |
#tracks ⇒ Object (readonly)
Returns the value of attribute tracks.
31 32 33 |
# File 'lib/device/magnetic.rb', line 31 def tracks @tracks end |
Class Method Details
.adapter ⇒ Object
3 4 5 |
# File 'lib/device/magnetic.rb', line 3 def self.adapter Device.adapter::Magnetic end |
.read_card(timeout) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/device/magnetic.rb', line 11 def self.read_card(timeout) time = Time.now + (timeout.to_f / 1000.0) magnetic = self.new loop do break if magnetic.swiped? || time <= Time.now end magnetic.tracks ensure magnetic.close if magnetic end |
Instance Method Details
#adapter ⇒ Object
7 8 9 |
# File 'lib/device/magnetic.rb', line 7 def adapter Device.adapter::Magnetic end |
#bin?(value) ⇒ Boolean
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/device/magnetic.rb', line 77 def bin?(value) return false if value.to_s.empty? tracks if self.read? digits = extract_digits(value) if value.is_a?(Range) && ! digits.empty? && digits.integer? value.include? digits.to_f else digits.to_s == value.to_s end end |
#close ⇒ Object
64 65 66 |
# File 'lib/device/magnetic.rb', line 64 def close adapter.close end |
#open? ⇒ Boolean
73 74 75 |
# File 'lib/device/magnetic.rb', line 73 def open? @open end |
#read ⇒ Object
60 61 62 |
# File 'lib/device/magnetic.rb', line 60 def read adapter.read end |
#read? ⇒ Boolean
56 57 58 |
# File 'lib/device/magnetic.rb', line 56 def read? @status == STATUS_SUCCESSFUL_READ end |
#start ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/device/magnetic.rb', line 38 def start if self.adapter.open == HARDWARE_RET_OK @status = STATUS_OPEN true else @status = STATUS_OPEN_FAIL false end end |
#swiped? ⇒ Boolean
48 49 50 51 52 53 54 |
# File 'lib/device/magnetic.rb', line 48 def swiped? if self.read == HARDWARE_SUCCESSFUL_READ @status = STATUS_SUCCESSFUL_READ return true end false end |