diff --git a/lib/biju.rb b/lib/biju.rb index a2abf13..89ad972 100644 --- a/lib/biju.rb +++ b/lib/biju.rb @@ -1,5 +1,2 @@ -require "biju/version" - -module Biju - # Your code goes here... -end +require 'biju/version' +require "biju/sms" diff --git a/lib/biju/sms.rb b/lib/biju/sms.rb new file mode 100644 index 0000000..175ab8b --- /dev/null +++ b/lib/biju/sms.rb @@ -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 diff --git a/spec/biju/sms_spec.rb b/spec/biju/sms_spec.rb new file mode 100644 index 0000000..0cca416 --- /dev/null +++ b/spec/biju/sms_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d0649f8 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'minitest/autorun' +require "./lib/biju" \ No newline at end of file