Add compatibility with ruby 1.9.3

develop
Guillaume DOTT 2013-11-06 17:26:26 +01:00
parent 6767b99b4a
commit e1e7be5d98
9 changed files with 37 additions and 14 deletions

View File

@ -26,7 +26,10 @@ module Biju
wait(length: 0, timeout: 0)
end
def wait(length: 0, timeout: 10)
def wait(options = {})
length = options[:length] || 0
timeout = options[:timeout] || 10
buffer = ''
Timeout.timeout(timeout) do
while IO.select([connection], [], [], 0.25) || buffer.length < length

View File

@ -11,7 +11,9 @@ require 'biju/pdu/type_of_address'
module Biju
module PDU
def self.encode(phone_number, message, type_of_address: :international)
def self.encode(phone_number, message, options = {})
type_of_address = options[:type_of_address] || :international
phone_number = PhoneNumber.encode(phone_number)
user_data = UserData.encode(message)
first_octet = FirstOctet.new.message_type_indicator!(:sms_submit)

View File

@ -1,3 +1,5 @@
# encoding: UTF-8
module Biju
module PDU
module Encoding
@ -28,7 +30,9 @@ module Biju
0x65 => '€',
}
def self.decode(string, length: 0)
def self.decode(string, options = {})
length = options[:length] || 0
res = ''
next_char = 0
current_length = 0
@ -98,7 +102,9 @@ module Biju
end
end
def self.get_septet(char, escape: false)
def self.get_septet(char, options = {})
escape = options[:escape] || false
char = (!escape ? BASIC_7BIT_CHARACTER_SET.index(char) : BASIC_7BIT_CHARACTER_SET_EXTENSION.key(char))
return nil unless char

View File

@ -2,7 +2,9 @@ module Biju
module PDU
module Encoding
class UCS2
def self.decode(string, length: 0)
def self.decode(string, options = {})
length = options[:length] || 0
string.scan(/.{4}/).map { |char| char.hex.chr('UCS-2BE') }.join
.encode('UTF-8', 'UCS-2BE')
end

View File

@ -3,7 +3,9 @@ module Biju
class PhoneNumber
attr_accessor :type_of_address, :number
def self.encode(number, type_of_address: :international)
def self.encode(number, options = {})
type_of_address = options[:type_of_address] || :international
number = number + 'F' if number.length.odd?
new(
number.scan(/../).map(&:reverse).join,
@ -11,7 +13,9 @@ module Biju
)
end
def initialize(number, type_of_address: :international)
def initialize(number, options = {})
type_of_address = options[:type_of_address] || :international
self.number = number
self.type_of_address = TypeOfAddress.new(type_of_address)
end

View File

@ -6,10 +6,10 @@ module Biju
ucs2: Encoding::UCS2,
}
attr_accessor :encoding, :message, :length
attr_accessor :encoding, :message, :length, :user_data_header
def self.encode(message, encoding: nil)
encoding = DataCodingScheme.autodetect(message) if encoding.nil?
def self.encode(message, options = {})
encoding = options[:encoding] || DataCodingScheme.autodetect(message)
raise ArgumentError, 'Unknown encoding' unless ENCODING.has_key?(encoding)
res = ENCODING[encoding].encode(message)
@ -17,10 +17,13 @@ module Biju
new(message: res[0], length: res[1][:length], encoding: encoding)
end
def initialize(message: '', length: 0, encoding: :gsm7bit)
self.encoding = DataCodingScheme.new(encoding)
self.message = message
self.length = length
def initialize(options = {})
self.encoding = DataCodingScheme.new(options[:encoding] || :gsm7bit)
self.message = options[:message] || ''
self.length = options[:length] || 0
self.user_data_header = options[:user_data_header] || false
end
def decode

View File

@ -1,3 +1,4 @@
# encoding: UTF-8
require 'spec_helper'
require 'biju/pdu'

View File

@ -1,3 +1,4 @@
# encoding: UTF-8
require 'spec_helper'
require 'biju/pdu/encoding/gsm7bit'

View File

@ -1,3 +1,4 @@
# encoding: UTF-8
require 'spec_helper'
require 'biju/pdu/encoding/ucs2'