Class: TexWarning
- Inherits:
-
Object
show all
- Defined in:
- lib/trex.rb
Overview
Direct Known Subclasses
BibtexWarning, CitationWarning, FontWarning, MissingParenthesisWarning, MultipleLabelWarning, OtherWarning, PDFVersionMismatchWarning, PharagraphEndedWarning, ReferenceWarning, RepeatedPageNumberWarning, TexError, TooManyWarning
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_error(line, string) ⇒ Object
-
#empty? ⇒ Boolean
-
#expand_input(string, index, lines) ⇒ Object
-
#extract_line(string, index, lines) ⇒ Object
-
#format_error(line, string) ⇒ Object
-
#format_warning_message(line, string) ⇒ Object
-
#handle(string, index = nil, lines = nil) ⇒ Object
-
#has_error?(line, string) ⇒ Boolean
-
#initialize(name, pattern, printPattern = /.*/, limit = 10, additionaInputLines = 0) ⇒ TexWarning
constructor
A new instance of TexWarning.
-
#render_line(line) ⇒ Object
-
#size ⇒ Object
-
#sort ⇒ Object
-
#to_s ⇒ Object
Constructor Details
#initialize(name, pattern, printPattern = /.*/, limit = 10, additionaInputLines = 0) ⇒ TexWarning
Returns a new instance of TexWarning.
571
572
573
574
575
576
577
578
579
580
|
# File 'lib/trex.rb', line 571
def initialize(name, pattern, printPattern=/.*/, limit=10,
additionaInputLines=0)
@name = name
@pattern = pattern
@printPattern = printPattern
@errors = []
@limit = limit
@maxLinesWidth = 0
@additionaInputLines = additionaInputLines
end
|
Instance Attribute Details
#filestate ⇒ Object
Returns the value of attribute filestate.
569
570
571
|
# File 'lib/trex.rb', line 569
def filestate
@filestate
end
|
#limit ⇒ Object
Returns the value of attribute limit.
568
569
570
|
# File 'lib/trex.rb', line 568
def limit
@limit
end
|
Instance Method Details
#add_error(line, string) ⇒ Object
613
614
615
616
617
618
|
# File 'lib/trex.rb', line 613
def add_error(line, string)
return if self.has_error?(line, string) line = self.render_line(line) unless line == "-"
@errors.push([line, string.to_s])
@maxLinesWidth = [@maxLinesWidth, line.size].max
end
|
#empty? ⇒ Boolean
674
675
676
|
# File 'lib/trex.rb', line 674
def empty?
self.size == 0
end
|
592
593
594
595
596
|
# File 'lib/trex.rb', line 592
def expand_input(string, index, lines)
return string if @additionaInputLines == 0
to = [index + @additionaInputLines, lines.size].min
return lines[index..to].join("\n") + "\n"
end
|
598
599
600
601
602
603
604
605
606
607
|
# File 'lib/trex.rb', line 598
def (string, index, lines)
if /line(?:s)? (?<line>[0-9\-]+)/ =~ string
return line
end
if /(?:line(?:s)? |l[^0-9])(?<line>[0-9\-]+)/ =~ string
return line
end
return "-"
end
|
645
646
647
648
|
# File 'lib/trex.rb', line 645
def format_error(line, string)
message = self.format_warning_message(line, string)
"#{line.ljust(@maxLinesWidth).yellow} #{message.to_s.chomp}"
end
|
650
651
652
653
654
655
656
657
658
|
# File 'lib/trex.rb', line 650
def format_warning_message(line, string)
if @printPattern.instance_of? Proc
puts self.class, @name
return @printPattern.call(line, string)
end
matched = @printPattern.match string
return string if not matched
return matched
end
|
#handle(string, index = nil, lines = nil) ⇒ Object
582
583
584
585
586
587
588
589
590
|
# File 'lib/trex.rb', line 582
def handle(string, index=nil, lines=nil)
if not string.match(@pattern) or string.empty?
return false
end
string = self.expand_input(string, index, lines)
line = self.(string, index, lines)
self.add_error(line, string)
true
end
|
#has_error?(line, string) ⇒ Boolean
620
621
622
623
624
625
|
# File 'lib/trex.rb', line 620
def has_error?(line, string)
@errors.each { |e|
return true if e[0] == line and e[1] == string
}
false
end
|
#render_line(line) ⇒ Object
609
610
611
|
# File 'lib/trex.rb', line 609
def render_line(line)
(@filestate and @filestate.state or "") + line.to_s
end
|
#size ⇒ Object
670
671
672
|
# File 'lib/trex.rb', line 670
def size
@errors.size
end
|
#sort ⇒ Object
660
661
662
663
664
665
666
667
668
|
# File 'lib/trex.rb', line 660
def sort
@errors.sort_by {|k|
k.to_s.split(/((?:(?:^|\s)[-+])?(?:\.\d+|\d+(?:\.\d+?(?:[eE]\d+)?(?:$|(?![eE\.])))?))/ms).
map {|v| Float(v) rescue v.downcase}
}
end
|
#to_s ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
|
# File 'lib/trex.rb', line 627
def to_s
if self.empty?
return ""
end
self.sort
limit = [@limit, @errors.size].min
str = @name.red.bold + " [#{@errors.size}]: "
str += "\n" limit.times { |i|
str += " #{self.format_error(@errors[i][0], @errors[i][1])}\n"
}
if @limit < @errors.size and @limit != 0
str += " #{"...".ljust(@maxLinesWidth)} ...\n"
end
str
end
|