Module: VEYCRECE::Question

Defined in:
lib/veycrece/veycrece.rb

Instance Method Summary collapse

Instance Method Details

#answer(answer) ⇒ Object



17
18
19
# File 'lib/veycrece/veycrece.rb', line 17

def answer(answer)
  read_tag(@question) === answer
end

#delete_extra_space(string) ⇒ Object



21
22
23
# File 'lib/veycrece/veycrece.rb', line 21

def delete_extra_space(string)
  string.split(' ').join(' ')
end

#load_tag(tag) ⇒ Object



9
10
11
# File 'lib/veycrece/veycrece.rb', line 9

def load_tag(tag)
        @tag = tag
end

#load_tags(tags) ⇒ Object



5
6
7
# File 'lib/veycrece/veycrece.rb', line 5

def load_tags(tags)
  @tags = tags
end

#question(question) ⇒ Object



13
14
15
# File 'lib/veycrece/veycrece.rb', line 13

def question(question)
  @question = question
end

#read_tag(string, type = false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/veycrece/veycrece.rb', line 25

def read_tag(string,type = false)
  #delete break lines  
  string.gsub(/\n/,"")
  #tag number is only number range 0-9
    string.gsub!(/\[\#number\]/i,"[0-9]+")
  #tag rcharacter accepts all type of character alphanumeric
    string.gsub!(/\[\#rcharacter\]/i,"[a-zA-Z]+")
  #tag characterm accepts all type of character alphanumeric lower case
    string.gsub!(/\[\#characterm\]/i,"[a-z]+")
  #tag characterM accepts all type of character alphanumeric Uppercase
     string.gsub!(/\[\#characterM\]/i,"[A-Z]+")
  #tag end line
     string.gsub!(/\[\#end\]/i,"\\z")
  #fix ( RegEx
     string.gsub!("(","[(]+")
  #fix ( Regex
     string.gsub!(")","[)]+") 
  #load single tag
           string.gsub!(Regexp.new(@tag[:tag]),@tag[:to])  if @tag

  #load multiple tags
        if @tags
            @tags.each do |hash|
           string.gsub!(Regexp.new(hash[:tag]),hash[:to]) 
            end
          end

  #constraint required
     string = "^#{string}$"

     case type
     when "?" then
    #if type is ? ignore case sensitive
        Regexp.new(string,Regexp::IGNORECASE)
     else
      Regexp.new(string)

     end   

end