Class: MSR::Track

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeObject

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.

Parameters:

  • other (Track)

    the track to compare to

Returns:

  • (Boolean)

    true if the two are equal, false otherwise



31
32
33
34
# File 'lib/msr/track.rb', line 31

def ==(other)
  return unless other.is_a?(self.class)
  data == other.data
end

#dataArray<Fixnum>

The data associated with the track.

Returns:

  • (Array<Fixnum>)

    the track data



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.

Returns:

  • (Boolean)

    true if empty, false otherwise



8
9
10
# File 'lib/msr/track.rb', line 8

def empty?
  data.empty?
end

#lengthFixnum

The length of the track's data.

Returns:

  • (Fixnum)

    the track length



13
# File 'ext/msr/track.c', line 13

static VALUE msr_track_get_length(VALUE self);

#reverseMSR::Track

Reverse the direction of the track, returning a new object.

Returns:



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.

Returns:



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_sString

Note:

May or may not be human readable.

Return a string representation of the track's data.

Returns:

  • (String)

    a string representation of track data



23
24
25
# File 'lib/msr/track.rb', line 23

def to_s
  data.map(&:chr).join
end