tokenizr 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13cec7d75e671b52b1650344411364237ad776aa
4
- data.tar.gz: 20cef2cd9af0c96af86755c3f7b589a699c7d9f5
3
+ metadata.gz: 3b263800218e29cf26e3a5626b278290a6c4c481
4
+ data.tar.gz: 5acfd3de31cfcf5ae5b5547cb0c9f628436bffff
5
5
  SHA512:
6
- metadata.gz: ec580aa5e40e9a7658acc9d451e6c2a352ef71c81e78a292a79842f202c42e3842f080a8601a0d09652aa1d1d60803560d38d86cede7c2d212ba9844fcc03675
7
- data.tar.gz: 6c91ae0b26e1074a9d617bd43f74e43e7ae6dc9bda014f19aa260e1e69d232f826543b3983945c981871ef1f4439bc7793666403c5cf7deba09b925291a2ce6d
6
+ metadata.gz: 95adfc1fe93f169bd052d341b73e7838af91d62146b62c81dbf73921347ce6c842a6e2b08f76e9e276354e977be02329a7d664443b00493fe39d72ae7cf01031
7
+ data.tar.gz: e892056c8b8dd407272955b2280a90317d6552417d3fe50a611487c23cd80c1898ef95464879493616d3047339ff2f9ce64403ef2ceeaa6cbd0ba52bc23557c6
data/lib/tokenizr.rb CHANGED
@@ -35,6 +35,10 @@ module Tokenizr
35
35
  ret.to_s[1..-1].to_i
36
36
  end
37
37
 
38
+ def self.valid_token?(token)
39
+ token.class == String && token.length == Tokenizr.encode(1).length
40
+ end
41
+
38
42
 
39
43
  private
40
44
 
@@ -1,3 +1,3 @@
1
1
  module Tokenizr
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -2,7 +2,7 @@ require_relative '../lib/tokenizr'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  class TokenizrTest < MiniTest::Unit::TestCase
5
- describe '#encode' do
5
+ describe '.encode' do
6
6
  it 'encodes the given number into a string' do
7
7
  assert_equal Tokenizr.encode(123), "5IbEL8X9e"
8
8
  assert_equal Tokenizr.encode(987654321), "VGh4Q9X9e"
@@ -34,7 +34,7 @@ class TokenizrTest < MiniTest::Unit::TestCase
34
34
  end
35
35
  end
36
36
 
37
- describe '#decode' do
37
+ describe '.decode' do
38
38
  it 'decodes the given string into a number' do
39
39
  assert_equal Tokenizr.decode("5IbEL8X9e"), 123
40
40
  assert_equal Tokenizr.decode("VGh4Q9X9e"), 987654321
@@ -46,4 +46,18 @@ class TokenizrTest < MiniTest::Unit::TestCase
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe '.valid_token?' do
51
+ it 'returns true for valid tokens' do
52
+ ["5IbEL8X9e", "VGh4Q9X9e"].each do |token|
53
+ assert_equal Tokenizr.valid_token?(token), true
54
+ end
55
+ end
56
+
57
+ it 'returns false for invalid tokens' do
58
+ [nil, 123, 1.23, [], {}, ''].each do |token|
59
+ assert_equal Tokenizr.valid_token?(token), false
60
+ end
61
+ end
62
+ end
49
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokenizr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - arktisklada