squarecoder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Aaron Breckenridge
1
+ Copyright (c) 2011-2013 Aaron Breckenridge
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -5,7 +5,7 @@ Squarecoder encapsulates a Squarecoder::Transcoder singleton that encodes and de
5
5
  == Installation
6
6
 
7
7
  $ gem install squarecoder
8
-
8
+
9
9
  Or
10
10
 
11
11
  # in Gemfile
@@ -22,5 +22,5 @@ Or
22
22
 
23
23
  == Copyright
24
24
 
25
- Copyright (c) 2011 Aaron Breckenridge. See LICENSE.txt for
25
+ Copyright (c) 2011-2013 Aaron Breckenridge. See LICENSE.txt for
26
26
  further details.
@@ -2,8 +2,8 @@ require 'rubygems'
2
2
  require 'singleton'
3
3
 
4
4
  module Squarecoder
5
- # Maximum length of an input string
6
- MAX_LEN = 81
5
+ # Maximum length of an input string
6
+ MAX_LEN = 81
7
7
  require 'squarecoder/core_ext/string'
8
8
  require 'squarecoder/errors'
9
9
  require 'squarecoder/transcoder'
@@ -1,16 +1,16 @@
1
1
  class String
2
-
2
+
3
3
  # Convert a String to a Grouped array of Characters of a specific length
4
- #
4
+ #
5
5
  # Example:
6
- #
6
+ #
7
7
  # "abcdefgh".in_character_arrays_of_length(3) # => [["a","b","c"],["d","e","f"],["g","h"]]
8
- #
8
+ #
9
9
  # Returns an Array.
10
- def in_character_arrays_of_length( length )
11
- scan( /./ ).each_slice( length ).to_a
10
+ def in_character_arrays_of_length(length)
11
+ scan(/./).each_slice(length).to_a
12
12
  end
13
-
13
+
14
14
  # Encode a String
15
15
  def square_encode
16
16
  dup.square_encode!
@@ -18,17 +18,17 @@ class String
18
18
 
19
19
  # Encode a String (in-place)
20
20
  def square_encode!
21
- replace( Squarecoder::Transcoder.encode( self ) )
21
+ replace(Squarecoder::Transcoder.encode(self))
22
22
  end
23
-
23
+
24
24
  # Decode an encoded String
25
25
  def square_decode
26
26
  dup.square_decode!
27
27
  end
28
-
28
+
29
29
  # Decode a string (in-place)
30
30
  def square_decode!
31
- replace( Squarecoder::Transcoder.decode( self ) )
31
+ replace(Squarecoder::Transcoder.decode(self))
32
32
  end
33
-
33
+
34
34
  end
@@ -1,7 +1,7 @@
1
1
  module Squarecoder
2
2
  class InputTooLong < StandardError # :nodoc:
3
3
  end
4
-
4
+
5
5
  class NoWhitespace < StandardError # :nodoc:
6
6
  end
7
7
  end
@@ -1,17 +1,15 @@
1
1
  module Squarecoder
2
-
2
+
3
3
  # A Transcoder is a Singleton used to encode and decode strings.
4
- #
4
+ #
5
5
  # Examples
6
- #
6
+ #
7
7
  # Squarecoder::Transcoder.encode("haveaniceday") # => "hae and via ecy"
8
8
  # Squarecoder::Transcoder.decode("hae and via ecy") # => "haveaniceday"
9
9
  # "haveaniceday".square_encode # => "hae and via ecy"
10
10
  # "hae and via ecy".square_decode # => "haveaniceday"
11
11
  class Transcoder
12
-
13
- include Singleton
14
-
12
+
15
13
  # Encode a String in square code
16
14
  def self.encode a_string, ignore_whitespace = false, ignore_max_length = false
17
15
  if !ignore_max_length && a_string.length > MAX_LEN
@@ -20,19 +18,19 @@ module Squarecoder
20
18
  if !ignore_whitespace && a_string.include?(' ')
21
19
  raise Squarecoder::NoWhitespace
22
20
  end
23
- len = ( a_string.length ** ( 0.5 ) ).ceil
24
- arry = a_string.in_character_arrays_of_length( len )
21
+ len = (a_string.length ** (0.5)).ceil
22
+ arry = a_string.in_character_arrays_of_length(len)
25
23
  if arry.last.length != len
26
- ( len - arry.last.length ).times { arry.last << ' ' } # a tiny bit faster than arry.fill
24
+ (len - arry.last.length).times { arry.last << ' ' } # a tiny bit faster than arry.fill
27
25
  end
28
26
  arry.transpose.collect { |line| line.join }.join(' ').rstrip
29
27
  end
30
-
28
+
31
29
  # Decode a String from square code
32
30
  def self.decode a_string
33
- encode( a_string, true, true ).gsub(/ +/, '')
31
+ encode(a_string, true, true).gsub(/ +/, '')
34
32
  end
35
-
33
+
36
34
  end
37
-
35
+
38
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squarecoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-28 00:00:00.000000000Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A library to encode and decode strings using the square code encryption
15
15
  method.
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: 1.3.6
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 1.8.11
50
+ rubygems_version: 1.8.24
51
51
  signing_key:
52
52
  specification_version: 3
53
53
  summary: encode and decode strings using the square code encryption method