Class: GreenPepper::FreeTextKeyword

Inherits:
Object
  • Object
show all
Defined in:
lib/greenpepper/freetext.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex, block, convert) ⇒ FreeTextKeyword

Returns a new instance of FreeTextKeyword.

Raises:

  • (ArgumentError)


95
96
97
98
99
# File 'lib/greenpepper/freetext.rb', line 95

def initialize(regex, block, convert)
  raise ArgumentError.new unless regex.is_a? Regexp
  raise ArgumentError.new unless block.is_a? Proc
  @regex, @block, @convert = regex, block, convert
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



92
93
94
# File 'lib/greenpepper/freetext.rb', line 92

def block
  @block
end

#regexObject (readonly)

Returns the value of attribute regex.



92
93
94
# File 'lib/greenpepper/freetext.rb', line 92

def regex
  @regex
end

#resultObject

Returns the value of attribute result.



93
94
95
# File 'lib/greenpepper/freetext.rb', line 93

def result
  @result
end

Instance Method Details

#args(action) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/greenpepper/freetext.rb', line 105

def args(action)
  args = @regex.match(action)[1..-1]

  args.collect!{ |arg|
    TypeConverter.instance.convert_string(arg) 
  } if @convert

  args
end

#match?(action) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/greenpepper/freetext.rb', line 101

def match?(action)
  @regex === action
end