gsm_encoder 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/lib/gsm_encoder.rb +5 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afd16680c9add39fa0f0a6b40e0a5674df79ffdc
4
- data.tar.gz: 27b2dbd76a63054ae29fdab05730ff7aa9342c53
3
+ metadata.gz: 8528761bc6678e5796d054214f545f5df324a43b
4
+ data.tar.gz: 02ef6f2bbac3cadeba4623fb82f8f0b531236b5a
5
5
  SHA512:
6
- metadata.gz: 91ea6159220788a7ff282a8ebb833b51901a0b9ca1b233de0222d7295e9a700a51d5e5d0cdfd0b9d4e8984b22f50e6a85769b14f8a595152fa0e59d6053399e4
7
- data.tar.gz: b8bf806da9c5fead874c7db1253d62801badd906035bcf42c053611cab8003585c6951d58da68c4ce5b34ccac68bdf07ce54a999bf64a7202083ff988991153c
6
+ metadata.gz: 883a895ea777489a58d96118f9029a46f1c21c0d4bf0b381a3d11c64f0fadc1e7361be0d65bdc3ef029ed7605a3093456038d7acc4530160724342e67f3e36c5
7
+ data.tar.gz: 5d2255dc35d094c44c59c8d8123d1490cb6f1af5e4c67509d6253aadd77595b2b9291709bf3e7eae3c5ae61ac9602ab58ff0c6b85f37cd2f4d1d362ce96f29b6
data/README.md CHANGED
@@ -26,6 +26,9 @@ __NOTE: ruby >= 1.9.2 is required__
26
26
  # replaces unsupported chars with '?'
27
27
  GSMEncoder.encode('`') # => '?'
28
28
 
29
+ # replaces unsupported chars with a provided value ' '
30
+ GSMEncoder.encode('`', ' ') # => ' '
31
+
29
32
  ## Updates
30
33
 
31
34
  ### 0.1.1
@@ -35,3 +38,8 @@ Added support for Spanish shift
35
38
  ### 0.1.2
36
39
 
37
40
  Fixed bug when encoding line feed & carriage return
41
+
42
+ ## 0.1.3
43
+
44
+ Adds the ability to provide the character used when encoding
45
+ unsupported strings
data/lib/gsm_encoder.rb CHANGED
@@ -7,6 +7,7 @@
7
7
  # alphabet. It also supports the default extension table. The default alphabet
8
8
  # and it's extension table is defined in GSM 03.38.
9
9
  module GSMEncoder
10
+ DEFAULT_REPLACE_CHAR = "?"
10
11
 
11
12
  EXTENDED_ESCAPE = 0x1b
12
13
  NL = 10.chr
@@ -78,9 +79,11 @@ module GSMEncoder
78
79
  true
79
80
  end
80
81
 
81
- def encode str
82
+ def encode(str, replace_char=nil)
82
83
  return nil if !str
83
84
 
85
+ replace_char = DEFAULT_REPLACE_CHAR if !replace_char || !can_encode?(replace_char)
86
+
84
87
  buffer = ''.encode('binary')
85
88
 
86
89
  begin
@@ -103,7 +106,7 @@ module GSMEncoder
103
106
  search += 1
104
107
  end
105
108
  if search == CHAR_TABLE.length
106
- buffer << '?'
109
+ buffer << replace_char
107
110
  end
108
111
  end
109
112
  rescue
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gsm_encoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Korolev
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-13 00:00:00.000000000 Z
12
+ date: 2013-03-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: GSMEncoder encodes and decodes Ruby Strings to and from the SMS default
15
15
  alphabet. It also supports the default extension table. The default alphabet and