Class: Commandorobo::Invoker
- Inherits:
-
Object
- Object
- Commandorobo::Invoker
- Defined in:
- lib/commandorobo.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #check(text) ⇒ Object
-
#extrapolate(text) ⇒ Object
I WANT AN EXCUSE TO SAY EXTRAPOLATE OK.
-
#initialize(val, type, **kwargs) ⇒ Invoker
constructor
A new instance of Invoker.
- #match(text) ⇒ Object
Constructor Details
#initialize(val, type, **kwargs) ⇒ Invoker
Returns a new instance of Invoker.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/commandorobo.rb', line 28 def initialize(val, type, **kwargs) if type == :regex val = Regexp::new(val) end if !kwargs[:sep].nil? && type == :dual val = val.split(kwargs[:sep]) end @value = val @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/commandorobo.rb', line 27 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
27 28 29 |
# File 'lib/commandorobo.rb', line 27 def value @value end |
Instance Method Details
#check(text) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/commandorobo.rb', line 59 def check(text) case @type when :prefix return text.start_with? @value when :suffix return text.end_with? @value when :dual return text.start_with?(@value[0]) && text.end_with?(@value[1]) when :regex return !self.match(text).nil? end end |
#extrapolate(text) ⇒ Object
I WANT AN EXCUSE TO SAY EXTRAPOLATE OK
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/commandorobo.rb', line 46 def extrapolate(text) # I WANT AN EXCUSE TO SAY EXTRAPOLATE OK case @type when :prefix return text[@value.length..text.length] when :suffix return text[0..-@value.length-1] when :dual return text[@value[0].length..-@value[1].length-1] when :regex return self.match(text) end end |
#match(text) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/commandorobo.rb', line 39 def match(text) if @type != :regex raise "Incorrect type for function." end return @value.match(text) end |