Class: MSR::Track
- Inherits:
-
Object
- Object
- MSR::Track
- Defined in:
- lib/msr/track.rb,
ext/msr/track.c
Overview
Represents a single track from a magnetic stripe card.
Constant Summary collapse
- MAX_TRACK_LEN =
INT2NUM(MSR_MAX_TRACK_LEN)
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare two tracks for equality.
-
#data ⇒ Array<Fixnum>
The data associated with the track.
-
#empty? ⇒ Boolean
Whether or not the track contains any data.
- #initialize ⇒ Object constructor
-
#length ⇒ Fixnum
The length of the track's data.
-
#reverse ⇒ MSR::Track
Reverse the direction of the track, returning a new object.
-
#reverse! ⇒ MSR::Tracks
Reverse the direction of the track, in place.
-
#to_s ⇒ String
Return a string representation of the track's data.
Constructor Details
#initialize ⇒ Object
Instance Method Details
#==(other) ⇒ Boolean
Compare two tracks for equality. Two tracks are said to be equal if they contain the same data, in the same order.
31 32 33 34 |
# File 'lib/msr/track.rb', line 31 def ==(other) return unless other.is_a?(self.class) data == other.data end |
#data ⇒ Array<Fixnum>
The data associated with the track.
7 |
# File 'ext/msr/track.c', line 7 static VALUE msr_track_get_data(VALUE self); |
#empty? ⇒ Boolean
Whether or not the track contains any data.
8 9 10 |
# File 'lib/msr/track.rb', line 8 def empty? data.empty? end |
#length ⇒ Fixnum
The length of the track's data.
13 |
# File 'ext/msr/track.c', line 13 static VALUE msr_track_get_length(VALUE self); |
#reverse ⇒ MSR::Track
Reverse the direction of the track, returning a new object.
19 |
# File 'ext/msr/track.c', line 19 static VALUE msr_track_reverse(VALUE self); |
#reverse! ⇒ MSR::Tracks
Reverse the direction of the track, in place.
14 15 16 17 18 |
# File 'lib/msr/track.rb', line 14 def reverse! @data = reverse.data self # return ourself, just for convenience end |
#to_s ⇒ String
May or may not be human readable.
Return a string representation of the track's data.
23 24 25 |
# File 'lib/msr/track.rb', line 23 def to_s data.map(&:chr).join end |