msr 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d6988a2d59a42e9eb5c923d392e59d1ae186ef
4
- data.tar.gz: 52d9c1e5eb38d71a7bae4a114cad60e053989de6
3
+ metadata.gz: d4eb31ded5a7a86fb1df60165558754f030223c1
4
+ data.tar.gz: 4474f8b073728ae16149b5ec1b8e1ef65496306a
5
5
  SHA512:
6
- metadata.gz: f2d87225574756678fc7b19f4deb5fe8babb5941b0160caec2b6ee3dbacc65f5e9205e1db8090ab16fa0eb597b897fa8c89af415a396311af4bb94068b5b8500
7
- data.tar.gz: e0e3ac7659268b2c6e82c904b7854ab91f5b2941b92089aea468fed7fbca844b657ed3b38d3205cb2c4dfaf4924f099fad8d65b23b9680ac1fcab9876ce6ee1b
6
+ metadata.gz: 8adb3783abdfb4731a671a2ddbe202fe0430992cb44dedb93ec452d4bcfa7f29083e00ac3f4823c40f90906e6be42c2b893dec06b7d67138526d49a5c39299c7
7
+ data.tar.gz: fd5505b6c8510bbadffd60737bfbf6260e52820f72eca3b95f2b7857a1255960164f40446ca428c1e77a73ca3b8a558ead9dcee685620431fd7e8e76008433ae
@@ -4,13 +4,13 @@
4
4
  The data associated with the track.
5
5
  @return [Array<Fixnum>] the track data
6
6
  */
7
- static VALUE msr_track_data(VALUE self);
7
+ static VALUE msr_track_get_data(VALUE self);
8
8
 
9
9
  /*
10
10
  The length of the track's data.
11
11
  @return [Fixnum] the track length
12
12
  */
13
- static VALUE msr_track_length(VALUE self);
13
+ static VALUE msr_track_get_length(VALUE self);
14
14
 
15
15
  /*
16
16
  Reverse the direction of the track, returning a new object.
@@ -27,8 +27,8 @@ void Init_msr_track()
27
27
  rb_define_const(c_MSR_Track, "MAX_TRACK_LEN", INT2NUM(MSR_MAX_TRACK_LEN));
28
28
 
29
29
  rb_define_method(c_MSR_Track, "initialize", msr_track_initialize, 1);
30
- rb_define_method(c_MSR_Track, "data", msr_track_data, 0);
31
- rb_define_method(c_MSR_Track, "length", msr_track_length, 0);
30
+ rb_define_method(c_MSR_Track, "data", msr_track_get_data, 0);
31
+ rb_define_method(c_MSR_Track, "length", msr_track_get_length, 0);
32
32
  rb_define_method(c_MSR_Track, "reverse", msr_track_reverse, 0);
33
33
  }
34
34
 
@@ -53,12 +53,12 @@ VALUE msr_track_initialize(VALUE self, VALUE tk_data_ary)
53
53
  return self;
54
54
  }
55
55
 
56
- static VALUE msr_track_data(VALUE self)
56
+ static VALUE msr_track_get_data(VALUE self)
57
57
  {
58
58
  return rb_iv_get(self, "@data");
59
59
  }
60
60
 
61
- static VALUE msr_track_length(VALUE self)
61
+ static VALUE msr_track_get_length(VALUE self)
62
62
  {
63
63
  VALUE tk_data_ary = rb_iv_get(self, "@data");
64
64
 
@@ -4,19 +4,25 @@
4
4
  The first track on the card.
5
5
  @return [MSR::Track] the track object
6
6
  */
7
- static VALUE msr_tracks_track1(VALUE self);
7
+ static VALUE msr_tracks_get_track1(VALUE self);
8
8
 
9
9
  /*
10
10
  The second track on the card.
11
11
  @return [MSR::Track] the track object
12
12
  */
13
- static VALUE msr_tracks_track2(VALUE self);
13
+ static VALUE msr_tracks_get_track2(VALUE self);
14
14
 
15
15
  /*
16
16
  The third track on the card.
17
17
  @return [MSR::Track] the track object
18
18
  */
19
- static VALUE msr_tracks_track3(VALUE self);
19
+ static VALUE msr_tracks_get_track3(VALUE self);
20
+
21
+ /*
22
+ All tracks on the card, as an array.
23
+ @return [Array<MSR::Track>] all card tracks
24
+ */
25
+ static VALUE msr_tracks_get_tracks(VALUE self);
20
26
 
21
27
  /*
22
28
  Reverse the direction of the tracks, returning a new object.
@@ -33,14 +39,17 @@ void Init_msr_tracks()
33
39
  rb_define_const(c_MSR_Tracks, "MAX_TRACKS", INT2NUM(MSR_MAX_TRACKS));
34
40
 
35
41
  rb_define_method(c_MSR_Tracks, "initialize", msr_tracks_initialize, 3);
36
- rb_define_method(c_MSR_Tracks, "track1", msr_tracks_track1, 0);
37
- rb_define_method(c_MSR_Tracks, "track2", msr_tracks_track2, 0);
38
- rb_define_method(c_MSR_Tracks, "track3", msr_tracks_track3, 0);
42
+ rb_define_method(c_MSR_Tracks, "track1", msr_tracks_get_track1, 0);
43
+ rb_define_method(c_MSR_Tracks, "track2", msr_tracks_get_track2, 0);
44
+ rb_define_method(c_MSR_Tracks, "track3", msr_tracks_get_track3, 0);
45
+ rb_define_method(c_MSR_Tracks, "tracks", msr_tracks_get_tracks, 0);
39
46
  rb_define_method(c_MSR_Tracks, "reverse", msr_tracks_reverse, 0);
40
47
  }
41
48
 
42
49
  VALUE msr_tracks_initialize(VALUE self, VALUE tk1, VALUE tk2, VALUE tk3)
43
50
  {
51
+ VALUE tks_ary = rb_ary_new();
52
+
44
53
  if (CLASS_OF(tk1) != c_MSR_Track) {
45
54
  rb_raise(rb_eArgError, "expected track object for track 1");
46
55
  }
@@ -53,26 +62,33 @@ VALUE msr_tracks_initialize(VALUE self, VALUE tk1, VALUE tk2, VALUE tk3)
53
62
  rb_raise(rb_eArgError, "expected track object for track 3");
54
63
  }
55
64
 
56
- rb_iv_set(self, "@track1", tk1);
57
- rb_iv_set(self, "@track2", tk2);
58
- rb_iv_set(self, "@track3", tk3);
65
+ rb_ary_push(tks_ary, tk1);
66
+ rb_ary_push(tks_ary, tk2);
67
+ rb_ary_push(tks_ary, tk3);
68
+
69
+ rb_iv_set(self, "@tracks", tks_ary);
59
70
 
60
71
  return self;
61
72
  }
62
73
 
63
- static VALUE msr_tracks_track1(VALUE self)
74
+ static VALUE msr_tracks_get_track1(VALUE self)
75
+ {
76
+ return rb_ary_entry(rb_iv_get(self, "@tracks"), 0);
77
+ }
78
+
79
+ static VALUE msr_tracks_get_track2(VALUE self)
64
80
  {
65
- return rb_iv_get(self, "@track1");
81
+ return rb_ary_entry(rb_iv_get(self, "@tracks"), 1);
66
82
  }
67
83
 
68
- static VALUE msr_tracks_track2(VALUE self)
84
+ static VALUE msr_tracks_get_track3(VALUE self)
69
85
  {
70
- return rb_iv_get(self, "@track2");
86
+ return rb_ary_entry(rb_iv_get(self, "@tracks"), 2);
71
87
  }
72
88
 
73
- static VALUE msr_tracks_track3(VALUE self)
89
+ static VALUE msr_tracks_get_tracks(VALUE self)
74
90
  {
75
- return rb_iv_get(self, "@track3");
91
+ return rb_iv_get(self, "@tracks");
76
92
  }
77
93
 
78
94
  static VALUE msr_tracks_reverse(VALUE self)
data/lib/msr.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../ext/msr/msr"
2
4
  require_relative "msr/track"
3
5
  require_relative "msr/tracks"
@@ -5,5 +7,5 @@ require_relative "msr/msr206"
5
7
  require_relative "msr/msr505c"
6
8
 
7
9
  module MSR
8
- VERSION = "0.0.4".freeze
10
+ VERSION = "0.1.0"
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MSR
2
4
  # Represents a connection to an MSR206 (or MSR206-compatible device).
3
5
  class MSR206
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MSR
2
4
  # Alias MSR505C to MSR206, since the two are firmware compatible.
3
5
  # @see MSR206
@@ -1,22 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MSR
2
4
  # Represents a single track from a magnetic stripe card.
3
5
  class Track
6
+ # Whether or not the track contains any data.
7
+ # @return [Boolean] `true` if empty, `false` otherwise
8
+ def empty?
9
+ data.empty?
10
+ end
11
+
4
12
  # Reverse the direction of the track, in place.
5
13
  # @return [MSR::Tracks] the current instance
6
14
  def reverse!
7
- reversed = self.reverse
8
-
9
- @data = reversed.data
15
+ @data = reverse.data
10
16
 
11
17
  self # return ourself, just for convenience
12
18
  end
13
19
 
20
+ # Return a string representation of the track's data.
21
+ # @note May or may not be human readable.
22
+ # @return [String] a string representation of track data
23
+ def to_s
24
+ data.map(&:chr).join
25
+ end
26
+
14
27
  # Compare two tracks for equality. Two tracks are said to be equal if they
15
28
  # contain the same data, in the same order.
29
+ # @param other [Track] the track to compare to
16
30
  # @return [Boolean] `true` if the two are equal, `false` otherwise
17
- def ==(o)
18
- return unless o.is_a?(self.class)
19
- data == o.data
31
+ def ==(other)
32
+ return unless other.is_a?(self.class)
33
+ data == other.data
20
34
  end
21
35
  end
22
36
  end
@@ -1,24 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MSR
2
4
  # Represents (up to) three tracks from a magnetic stripe card.
3
5
  class Tracks
6
+ # Whether or not all tracks are empty.
7
+ # @return [Boolean] `true` if all tracks are empty, `false` otherwise
8
+ def empty?
9
+ tracks.all?(&:empty?)
10
+ end
11
+
4
12
  # Reverse the direction of the tracks, in place.
5
13
  # @return [MSR::Tracks] the current instance
6
14
  def reverse!
7
- reversed = self.reverse
8
-
9
- @track1 = reversed.track1
10
- @track2 = reversed.track2
11
- @track3 = reversed.track3
15
+ @tracks = reverse.tracks
12
16
 
13
17
  self # return ourself, just for convenience
14
18
  end
15
19
 
16
20
  # Compare two sets of tracks for equality. Two sets are said to be equal
17
21
  # if all of their corresponding pairs are equal.
22
+ # @param other [Tracks] the tracks to compare to
18
23
  # @return [Boolean] `true` if the two are equal, `false` otherwise
19
- def ==(o)
20
- return unless o.is_a?(self.class)
21
- track1 == o.track1 && track2 == o.track2 && track3 == o.track3
24
+ def ==(other)
25
+ return unless other.is_a?(self.class)
26
+ track1 == other.track1 && track2 == other.track2 && track3 == other.track3
22
27
  end
23
28
  end
24
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-04 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for controlling magnetic stripe reader/writers.
14
14
  email: william@tuffbizz.com
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 2.5.1
54
+ rubygems_version: 2.6.11
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: msr - magnetic stripe reader/writer library.