at regex
parent
c087eb3973
commit
b17822b4eb
32
a.rb
32
a.rb
|
@ -6,7 +6,7 @@ $: << 'lib'
|
||||||
require 'biju'
|
require 'biju'
|
||||||
require 'pp'
|
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 = /
|
#re = /
|
||||||
# ( # capture the hostname in $1
|
# ( # capture the hostname in $1
|
||||||
# (?: # these parens for grouping only
|
# (?: # 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
|
# [\w-] + # now trailing domain part
|
||||||
# ) # end of $1 capture
|
# ) # end of $1 capture
|
||||||
# /x # /x for nice formatting
|
# /x # /x for nice formatting
|
||||||
re = /
|
#str = '((www.ruby-lang.org), (www.rubygarden.org), (www.co.com) ucou)'
|
||||||
( # capture the hostname in $1
|
strs = []
|
||||||
(?: # these parens for grouping only
|
strs << '((www.ruby-lang.org), (www.rubygarden.org), (www.co.com) (u)cou)'
|
||||||
(?! [-_] ) # lookahead for neither underscore nor dash
|
strs << '(www.ruby-lang.org), (www.rubygarden.org), (www.co.com) (u)'
|
||||||
[\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
|
|
||||||
|
|
||||||
|
re = /
|
||||||
|
\( # parenthese
|
||||||
|
(
|
||||||
|
#[^\(\)]*?
|
||||||
|
[\(\)]*?
|
||||||
|
.*?
|
||||||
|
)
|
||||||
|
\) # parenthese
|
||||||
|
/x
|
||||||
|
|
||||||
|
strs.each do |str|
|
||||||
|
pp "STR : #{str}"
|
||||||
str.gsub! re do # pass a block to execute replacement
|
str.gsub! re do # pass a block to execute replacement
|
||||||
pp $1
|
pp $1
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#exit
|
exit
|
||||||
|
|
||||||
puts "here"
|
puts "here"
|
||||||
hayes = Biju::HayesSms.new
|
hayes = Biju::HayesSms.new
|
||||||
|
|
|
@ -7,20 +7,20 @@ module Biju
|
||||||
#end
|
#end
|
||||||
|
|
||||||
def attention
|
def attention
|
||||||
basic_command { |response| response =~ /OK/ }
|
at_command { |response| response =~ /OK/ }
|
||||||
#basic_command { |response| true }
|
#at_command { |response| true }
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_modem
|
def init_modem
|
||||||
basic_command('Z') { |response| response =~ /OK/ }
|
at_command('Z') { |response| response =~ /OK/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_mode(enabled = true)
|
def text_mode(enabled = true)
|
||||||
extended_command('CMGF', enabled) { |response| response =~ /OK/ }
|
at_command('+CMGF', enabled) { |response| response =~ /OK/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
def prefered_storage?
|
def prefered_storage?
|
||||||
extended_command('CPMS') { |response| response =~ /OK/ }
|
at_command('+CPMS') { |response| response =~ /OK/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
def answer=(ret)
|
def answer=(ret)
|
||||||
|
@ -34,8 +34,8 @@ module Biju
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def basic_command(cmd = nil, options = {}, *args, &block)
|
def at_command(cmd = nil, *args, &block)
|
||||||
option_prefix = options[:prefix] || nil
|
option_prefix = nil #options[:prefix] || nil
|
||||||
cmd_root = ['AT', cmd].compact.join(option_prefix)
|
cmd_root = ['AT', cmd].compact.join(option_prefix)
|
||||||
cmd_args = args.compact.map { |arg| to_hayes_string(arg) } unless args.empty?
|
cmd_args = args.compact.map { |arg| to_hayes_string(arg) } unless args.empty?
|
||||||
self.command = [cmd_root, cmd_args].compact.join('=')
|
self.command = [cmd_root, cmd_args].compact.join('=')
|
||||||
|
@ -43,13 +43,10 @@ module Biju
|
||||||
command
|
command
|
||||||
end
|
end
|
||||||
|
|
||||||
def extended_command(cmd = nil, *args, &block)
|
|
||||||
basic_command(cmd, {:prefix => '+'}, *args, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def hayes_to_obj(str)
|
def hayes_to_obj(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# OPTIMIZE : add () to array
|
||||||
def to_hayes_string(arg)
|
def to_hayes_string(arg)
|
||||||
case arg
|
case arg
|
||||||
when String
|
when String
|
||||||
|
@ -66,7 +63,7 @@ module Biju
|
||||||
|
|
||||||
class HayesSms < Hayes
|
class HayesSms < Hayes
|
||||||
def unlock_pin(pin)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue