Class: SQLtorial::ValidColumnDirective

Inherits:
Object
  • Object
show all
Defined in:
lib/sqltorial/directives/valid_column_directive.rb

Constant Summary collapse

REGEXP =
/^ DIRECTIVE:\s*(\S+)\s+(\S+)\s+(.+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ ValidColumnDirective

Returns a new instance of ValidColumnDirective.



5
6
7
8
9
10
# File 'lib/sqltorial/directives/valid_column_directive.rb', line 5

def initialize(line)
  _, column, op, matcher = REGEXP.match(line).to_a
  @column = column.to_sym
  @op = op
  @matcher = Regexp.new(matcher)
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



4
5
6
# File 'lib/sqltorial/directives/valid_column_directive.rb', line 4

def column
  @column
end

#matcherObject (readonly)

Returns the value of attribute matcher.



4
5
6
# File 'lib/sqltorial/directives/valid_column_directive.rb', line 4

def matcher
  @matcher
end

#opObject (readonly)

Returns the value of attribute op.



4
5
6
# File 'lib/sqltorial/directives/valid_column_directive.rb', line 4

def op
  @op
end

Instance Method Details

#inspectObject



17
18
19
# File 'lib/sqltorial/directives/valid_column_directive.rb', line 17

def inspect
  [column, op, matcher].join(" ")
end

#validate(result) ⇒ Object



12
13
14
15
# File 'lib/sqltorial/directives/valid_column_directive.rb', line 12

def validate(result)
  md = matcher.match(result[column])
  op == '=' ? !md.nil? : md.nil?
end