diff --git a/a.rb b/a.rb index 55fc6aa..f287f46 100755 --- a/a.rb +++ b/a.rb @@ -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 - pp $1 +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 diff --git a/lib/biju/hayes.rb b/lib/biju/hayes.rb index 6f68bb1..ff5d0bb 100644 --- a/lib/biju/hayes.rb +++ b/lib/biju/hayes.rb @@ -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