Skip to content

Commit

Permalink
Merge pull request #8 from nysthee/feature/rubocop-style-fix
Browse files Browse the repository at this point in the history
Feature/rubocop style fix
  • Loading branch information
vladimir-tikhonov committed Apr 27, 2015
2 parents 81939d7 + 2a9d871 commit b13a005
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 40 deletions.
20 changes: 6 additions & 14 deletions lib/regexy/regexp.rb
Expand Up @@ -35,25 +35,17 @@ def + other
def bound(method = :both)
new_regexp = source
method = method.to_sym
if method == :left || method == :both
new_regexp.prepend('\A')
end
if method == :right || method == :both
new_regexp.concat('\z')
end
new_regexp.prepend('\A') if method == :left || method == :both
new_regexp.concat('\z') if method == :right || method == :both
new_regexp = additional_bound(method, new_regexp)
::Regexy::Regexp.new(new_regexp, options)
end

def unbound(method = :both)
new_regexp = source
method = method.to_sym
if method == :left || method == :both
new_regexp.sub!(/\A\\A/, '')
end
if method == :right || method == :both
new_regexp.sub!(/\\z\s*\z/, '')
end
new_regexp.sub!(/\A\\A/, '') if method == :left || method == :both
new_regexp.sub!(/\\z\s*\z/, '') if method == :right || method == :both
new_regexp = additional_unbound(method, new_regexp)
::Regexy::Regexp.new(new_regexp, options)
end
Expand All @@ -80,7 +72,7 @@ def additional_unbound(method, regex)
class RegexpWithMode < ::Regexy::Regexp
def initialize(mode = default_mode, *args)
regexp = regexp_for(mode.to_sym)
fail ArgumentError, "Unknown mode #{mode.to_s}" unless regexp
fail ArgumentError, "Unknown mode #{mode}" unless regexp
super(regexp, *args)
end

Expand All @@ -94,4 +86,4 @@ def default_mode
:normal
end
end
end
end
2 changes: 1 addition & 1 deletion lib/regexy/text.rb
Expand Up @@ -3,4 +3,4 @@ module Text
autoload :Smile, 'regexy/text/smile'
autoload :Emoji, 'regexy/text/emoji'
end
end
end
2 changes: 1 addition & 1 deletion lib/regexy/text/emoji.rb
Expand Up @@ -10,4 +10,4 @@ def initialize(*args)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/regexy/text/smile.rb
Expand Up @@ -8,4 +8,4 @@ def initialize(*args)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/regexy/web.rb
Expand Up @@ -7,4 +7,4 @@ module Web
autoload :Url, 'regexy/web/url'
autoload :HostName, 'regexy/web/host_name'
end
end
end
3 changes: 1 addition & 2 deletions lib/regexy/web/email.rb
Expand Up @@ -14,9 +14,8 @@ def regexp_for(mode)
when :relaxed then EMAIL_RELAXED
when :normal then EMAIL_NORMAL
when :strict then EMAIL_STRICT
else nil
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/regexy/web/hashtag.rb
Expand Up @@ -10,4 +10,4 @@ def initialize(*args)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/regexy/web/host_name.rb
Expand Up @@ -10,4 +10,4 @@ def initialize(*args)
end
end
end
end
end
6 changes: 2 additions & 4 deletions lib/regexy/web/ip.rb
Expand Up @@ -12,7 +12,6 @@ def regexp_for(mode)
case mode
when :normal then IPV4_NORMAL
when :with_port then IPV4_WITH_PORT
else nil
end
end
end
Expand All @@ -33,9 +32,8 @@ class IPv6 < ::Regexy::RegexpWithMode

def regexp_for(mode)
case mode
when :normal then IPV6_NORMAL
when :with_port then IPV6_WITH_PORT
else nil
when :normal then IPV6_NORMAL
when :with_port then IPV6_WITH_PORT
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/regexy/web/url.rb
Expand Up @@ -17,4 +17,4 @@ def initialize(*args)
end
end
end
end
end
9 changes: 4 additions & 5 deletions spec/regexp_spec.rb
Expand Up @@ -31,7 +31,7 @@
end

it 'mimics original regexp behaviour' do
#Fix for rubinius
# Fix for rubinius
expected_methods = ::Regexp.public_instance_methods(false) - [:initialize, :initialize_copy]
expect(Regexy::Regexp.public_instance_methods(false)).to include(*expected_methods)
end
Expand Down Expand Up @@ -107,7 +107,7 @@ class BoundCallbackCheck < Regexy::Regexp
protected

def additional_bound(method, regex)
"#{method.to_s}&#{regex}"
"#{method}&#{regex}"
end
end

Expand Down Expand Up @@ -137,7 +137,7 @@ class UnboundCallbackCheck < Regexy::Regexp
protected

def additional_unbound(method, regex)
"#{method.to_s}&#{regex}"
"#{method}&#{regex}"
end
end

Expand Down Expand Up @@ -174,7 +174,6 @@ def regexp_for(mode)
case mode
when :mode_1 then /mode_1/
when :mode_2 then /mode_2/
else nil
end
end

Expand Down Expand Up @@ -202,4 +201,4 @@ def default_mode
it 'fails when wrong mode is provided' do
expect { ValidRegex.new(:mode_3) }.to raise_error ArgumentError
end
end
end
2 changes: 1 addition & 1 deletion spec/text/emoji_spec.rb
Expand Up @@ -8,4 +8,4 @@
expect([p].pack('U*') =~ r).to be_truthy
end
end
end
end
2 changes: 1 addition & 1 deletion spec/text/smile_spec.rb
Expand Up @@ -32,4 +32,4 @@
expect(smile =~ r).to be_nil
end
end
end
end
2 changes: 1 addition & 1 deletion spec/web/email_spec.rb
Expand Up @@ -151,4 +151,4 @@
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/web/hashtag_spec.rb
Expand Up @@ -35,4 +35,4 @@
expect("##{hashtag}" =~ r).to be_nil
end
end
end
end
2 changes: 1 addition & 1 deletion spec/web/host_name_spec.rb
Expand Up @@ -35,4 +35,4 @@
expect(hostname =~ r).to be_nil
end
end
end
end
2 changes: 1 addition & 1 deletion spec/web/ip_spec.rb
Expand Up @@ -134,4 +134,4 @@
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/web/url_spec.rb
Expand Up @@ -47,7 +47,7 @@
'http:///a',
'http:// shouldfail.com',
':// should fail',
'http://foo.bar/foo(bar)baz quux',
'http://foo.bar/foo(bar)baz quux'
]

let(:r) { Regexy::Web::Url.new }
Expand All @@ -63,4 +63,4 @@
expect(url =~ r).to be_nil
end
end
end
end

0 comments on commit b13a005

Please sign in to comment.