Class: WarningSigns::OnlyExcept

Inherits:
Object
  • Object
show all
Defined in:
lib/warning_signs/only_except.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(only: [], except: []) ⇒ OnlyExcept

Returns a new instance of OnlyExcept.



5
6
7
8
# File 'lib/warning_signs/only_except.rb', line 5

def initialize(only: [], except: [])
  @only = only
  @except = except
end

Instance Attribute Details

#exceptObject

Returns the value of attribute except.



3
4
5
# File 'lib/warning_signs/only_except.rb', line 3

def except
  @except
end

#onlyObject

Returns the value of attribute only.



3
4
5
# File 'lib/warning_signs/only_except.rb', line 3

def only
  @only
end

Instance Method Details

#except_match?(message) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/warning_signs/only_except.rb', line 21

def except_match?(message)
  return true if except.empty?
  except.none? do |except_pattern|
    except_pattern.match?(message)
  end
end

#only_except_match?(message) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/warning_signs/only_except.rb', line 10

def only_except_match?(message)
  only_match?(message) && except_match?(message)
end

#only_match?(message) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/warning_signs/only_except.rb', line 14

def only_match?(message)
  return true if only.empty?
  only.any? do |only_pattern|
    only_pattern.match?(message)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/warning_signs/only_except.rb', line 28

def valid?
  except.empty? || only.empty?
end