develop
Thomas Kienlen 2013-02-28 22:55:59 +01:00 committed by Guillaume DOTT
parent c087eb3973
commit b17822b4eb
2 changed files with 30 additions and 27 deletions

34
a.rb
View File

@ -6,7 +6,7 @@ $: << 'lib'
require 'biju'
require 'pp'
str = 'www.ruby-lang.org and bonjour www.rubygarden.org coucou'
#str = 'www.ruby-lang.org and bonjour www.rubygarden.org coucou'
#re = /
# ( # capture the hostname in $1
# (?: # these parens for grouping only
@ -18,23 +18,29 @@ str = 'www.ruby-lang.org and bonjour www.rubygarden.org coucou'
# [\w-] + # now trailing domain part
# ) # end of $1 capture
# /x # /x for nice formatting
re = /
( # capture the hostname in $1
(?: # these parens for grouping only
(?! [-_] ) # lookahead for neither underscore nor dash
[\w-] + # hostname component
\. # and the domain dot
) + # now repeat that whole thing a bunch of times
[A-Za-z] # next must be a letter
[\w-] + # now trailing domain part
) # end of $1 capture
/x # /x for nice formatting
#str = '((www.ruby-lang.org), (www.rubygarden.org), (www.co.com) ucou)'
strs = []
strs << '((www.ruby-lang.org), (www.rubygarden.org), (www.co.com) (u)cou)'
strs << '(www.ruby-lang.org), (www.rubygarden.org), (www.co.com) (u)'
str.gsub! re do # pass a block to execute replacement
re = /
\( # parenthese
(
#[^\(\)]*?
[\(\)]*?
.*?
)
\) # parenthese
/x
strs.each do |str|
pp "STR : #{str}"
str.gsub! re do # pass a block to execute replacement
pp $1
end
end
#exit
exit
puts "here"
hayes = Biju::HayesSms.new

View File

@ -7,20 +7,20 @@ module Biju
#end
def attention
basic_command { |response| response =~ /OK/ }
#basic_command { |response| true }
at_command { |response| response =~ /OK/ }
#at_command { |response| true }
end
def init_modem
basic_command('Z') { |response| response =~ /OK/ }
at_command('Z') { |response| response =~ /OK/ }
end
def text_mode(enabled = true)
extended_command('CMGF', enabled) { |response| response =~ /OK/ }
at_command('+CMGF', enabled) { |response| response =~ /OK/ }
end
def prefered_storage?
extended_command('CPMS') { |response| response =~ /OK/ }
at_command('+CPMS') { |response| response =~ /OK/ }
end
def answer=(ret)
@ -34,8 +34,8 @@ module Biju
private
def basic_command(cmd = nil, options = {}, *args, &block)
option_prefix = options[:prefix] || nil
def at_command(cmd = nil, *args, &block)
option_prefix = nil #options[:prefix] || nil
cmd_root = ['AT', cmd].compact.join(option_prefix)
cmd_args = args.compact.map { |arg| to_hayes_string(arg) } unless args.empty?
self.command = [cmd_root, cmd_args].compact.join('=')
@ -43,13 +43,10 @@ module Biju
command
end
def extended_command(cmd = nil, *args, &block)
basic_command(cmd, {:prefix => '+'}, *args, &block)
end
def hayes_to_obj(str)
end
# OPTIMIZE : add () to array
def to_hayes_string(arg)
case arg
when String
@ -66,7 +63,7 @@ module Biju
class HayesSms < Hayes
def unlock_pin(pin)
send_command("AT+CPIN=#{to_hayes_string(pin)}") { |response| response =~ /OK/ }
at_command("+CPIN=#{to_hayes_string(pin)}") { |response| response =~ /OK/ }
end
end
end