Add Sms class and respective spec
parent
bbf6594b5e
commit
693613dfae
|
@ -1,5 +1,2 @@
|
||||||
require "biju/version"
|
require 'biju/version'
|
||||||
|
require "biju/sms"
|
||||||
module Biju
|
|
||||||
# Your code goes here...
|
|
||||||
end
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
module Biju
|
||||||
|
class Sms
|
||||||
|
attr_accessor :id, :phone_number, :datetime, :message
|
||||||
|
|
||||||
|
def initialize(params={})
|
||||||
|
params.each do |attr, value|
|
||||||
|
self.public_send("#{attr}=", value)
|
||||||
|
end if params
|
||||||
|
end
|
||||||
|
|
||||||
|
def datetime
|
||||||
|
@datetime.sub(/(\d+)\D+(\d+)\D+(\d+),(\d*\D)(\d*\D)(\d+)(.*)/, '20\1-\2-\3 \4\5\6')
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#{id} - #{phone_number} - #{datetime} - #{message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
|
describe Biju::Sms do
|
||||||
|
subject { Biju::Sms.new(:id => "1", :phone_number => "144", :datetime => "11/07/28,15:34:08-12", :message => "Some text here")}
|
||||||
|
|
||||||
|
it { subject.id.must_equal "1" }
|
||||||
|
|
||||||
|
it { subject.phone_number.must_equal "144" }
|
||||||
|
|
||||||
|
it { subject.datetime.must_equal "2011-07-28 15:34:08" }
|
||||||
|
|
||||||
|
it { subject.message.must_equal "Some text here" }
|
||||||
|
|
||||||
|
it { subject.to_s.must_equal "1 - 144 - 2011-07-28 15:34:08 - Some text here"}
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
require 'minitest/autorun'
|
||||||
|
require "./lib/biju"
|
Loading…
Reference in New Issue