From 1d4ce23ddbc457ec22345cb6d0bf61ee803f1eff Mon Sep 17 00:00:00 2001 From: Rodrigo Pinto Date: Fri, 18 May 2012 17:35:45 -0300 Subject: [PATCH] Start to doc modem class and put connectio method to private --- lib/biju/modem.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/biju/modem.rb b/lib/biju/modem.rb index f72ccbe..18353bd 100644 --- a/lib/biju/modem.rb +++ b/lib/biju/modem.rb @@ -3,6 +3,11 @@ require_relative 'sms' module Biju class Modem + + # Receives a hash of options where :port is mandatory + # + # Biju::Modem.new(:port => '/dev/ttyUSB0') + # def initialize(options={}) raise Exception.new("Port is required") unless options[:port] @connection = connection(options) @@ -10,15 +15,14 @@ module Biju cmd("AT+CMGF=1") end - def connection(options) - port = options.delete(:port) - SerialPort.new(port, default_options.merge!(options)) - end - + # Close the serial port connection. def close @connection.close end + # Returns an Array of Sms if there is messages, + # if not other way return nil + # def messages sms = cmd("AT+CMGL=\"ALL\"") msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/) @@ -27,6 +31,12 @@ module Biju end private + def connection(options) + port = options.delete(:port) + SerialPort.new(port, default_options.merge!(options)) + end + + # private method that generate default values for serial port connection def default_options { :baud => 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE } end