Class: CodeScanner
- Inherits:
-
Object
- Object
- CodeScanner
- Defined in:
- app/models/utils/codescanner.rb
Class Attribute Summary collapse
-
.scan_array ⇒ Object
readonly
Returns the value of attribute scan_array.
Class Method Summary collapse
- .array_range ⇒ Object
- .find_begin_range ⇒ Object
- .find_end_range ⇒ Object
- .find_title(index) ⇒ Object
- .run(scan_array, filename) ⇒ Object
- .strip_snip_tag(index) ⇒ Object
Class Attribute Details
.scan_array ⇒ Object (readonly)
Returns the value of attribute scan_array.
8 9 10 |
# File 'app/models/utils/codescanner.rb', line 8 def scan_array @scan_array end |
Class Method Details
.array_range ⇒ Object
38 39 40 41 42 |
# File 'app/models/utils/codescanner.rb', line 38 def self.array_range find_begin_range find_end_range @scan_array[@begin_scan+1..@end_scan-1].join end |
.find_begin_range ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/utils/codescanner.rb', line 16 def self.find_begin_range @scan_array.each_with_index do |line, index| if line.include?('<snip>') || line.include?('<$>') find_title(index) @line = index+1 strip_snip_tag(index) return @begin_scan = index end end return false end |
.find_end_range ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/models/utils/codescanner.rb', line 28 def self.find_end_range @scan_array.each_with_index do |line, index| if line.include?('</snip>') || line.include?('</$>') strip_snip_tag(index) return @end_scan = index end end return false end |
.find_title(index) ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/models/utils/codescanner.rb', line 51 def self.find_title(index) matches = @scan_array[index].match(/(<snip>|<\$>)(.+)/) if matches @title = matches[2].strip end @title end |
.run(scan_array, filename) ⇒ Object
9 10 11 12 13 14 |
# File 'app/models/utils/codescanner.rb', line 9 def self.run(scan_array, filename) @scan_array = scan_array while @scan_array.join.include?('<snip>') || @scan_array.join.include?('<$>') Snippet.new(code: array_range, title: @title, line: @line, filename: filename) end end |
.strip_snip_tag(index) ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/utils/codescanner.rb', line 44 def self.strip_snip_tag(index) @scan_array[index].sub!(/<snip>/,'<*snip*>') @scan_array[index].sub!(/<\/snip>/,'</*snip*>') @scan_array[index].sub!(/<\$>/,'<*$*>') @scan_array[index].sub!(/<\/\$>/,'</*$*>') end |