Add Sms class and respective spec

master
Rodrigo Pinto 2012-05-17 21:38:41 -03:00
parent bbf6594b5e
commit 693613dfae
4 changed files with 38 additions and 5 deletions

View File

@ -1,5 +1,2 @@
require "biju/version"
module Biju
# Your code goes here...
end
require 'biju/version'
require "biju/sms"

19
lib/biju/sms.rb 100644
View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
require 'minitest/autorun'
require "./lib/biju"