Class: Rule
- Inherits:
-
Object
show all
- Defined in:
- lib/rules/rule.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configurations ⇒ Object
Returns the value of attribute configurations.
10
11
12
|
# File 'lib/rules/rule.rb', line 10
def configurations
@configurations
end
|
.name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/rules/rule.rb', line 10
def name
@name
end
|
Class Method Details
.AnalyzeTokens(tokens) ⇒ Object
13
14
15
16
|
# File 'lib/rules/rule.rb', line 13
def self.AnalyzeTokens(tokens)
puts "Implement this"
return
end
|
.filter_resources(tokens, resources) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/rules/rule.rb', line 32
def self.filter_resources(tokens, resources)
is_resource = false
brackets = 0
ftokens=tokens.find_all do |hash|
if resources.include? hash.value.downcase
is_resource = true
elsif is_resource and hash.type.to_s == "LBRACE"
brackets += 1
elsif is_resource and hash.type.to_s == "RBRACE"
brackets -=1
end
if is_resource and hash.type.to_s == "RBRACE" and brackets == 0
is_resource = false
end
if !is_resource
(hash.type.to_s == 'NAME' || hash.type.to_s == 'VARIABLE' || hash.type.to_s == 'SSTRING' || hash.type.to_s == 'STRING')
end
end
return ftokens
end
|
.filter_tokens(tokens) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/rules/rule.rb', line 25
def self.filter_tokens(tokens)
ftokens=tokens.find_all do |hash|
(hash.type.to_s == 'SSTRING' || hash.type.to_s == 'STRING' || hash.type.to_s == 'VARIABLE' || hash.type.to_s == 'NAME')
end
return ftokens
end
|
.filter_variables(tokens, keywords) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rules/rule.rb', line 77
def self.filter_variables(tokens, keywords)
line = -1
kw_regex = Regexp.new keywords.join("|")
ftokens=tokens.find_all do |hash|
if (hash.type.to_s == 'VARIABLE' || hash.type.to_s == 'NAME') and hash.value.downcase =~ kw_regex
line = hash.line
elsif hash.line != line
hash
end
end
end
|
.filter_whitelist(tokens, whitelist) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/rules/rule.rb', line 70
def self.filter_whitelist(tokens, whitelist)
ftokens=tokens.find_all do |hash|
!(whitelist =~ hash.value.downcase)
end
return ftokens
end
|
63
64
65
66
67
68
|
# File 'lib/rules/rule.rb', line 63
def self.(tokens)
ftokens=tokens.find_all do |hash|
(hash.type.to_s == 'COMMENT' || hash.type.to_s == 'MLCOMMENT' || hash.type.to_s == 'SLASH_COMMENT')
end
return ftokens
end
|
.get_string_tokens(tokens, token) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/rules/rule.rb', line 56
def self.get_string_tokens(tokens, token)
ftokens=tokens.find_all do |hash|
(hash.type.to_s == 'SSTRING' || hash.type.to_s == 'STRING') and hash.value.downcase.include? token
end
return ftokens
end
|
.get_tokens(tokens, token) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/rules/rule.rb', line 18
def self.get_tokens(tokens, token)
ftokens=tokens.find_all do |hash|
(hash.type.to_s == 'NAME' || hash.type.to_s == 'VARIABLE' || hash.type.to_s == 'SSTRING' || hash.type.to_s == 'STRING') and hash.value.downcase.include? token
end
return ftokens
end
|
.inherited(subclass) ⇒ Object
5
6
7
|
# File 'lib/rules/rule.rb', line 5
def self.inherited(subclass)
subclass.configurations = [BooleanConfiguration.new("Enable Configuration", true, "Enable or disable the evaluation of the rules")]
end
|