Class: CachedResults
- Inherits:
-
Object
- Object
- CachedResults
- Defined in:
- lib/redparse/problemfiles.rb
Overview
redparse - a ruby parser written in ruby
Copyright (C) 2008, 2012, 2016 Caleb Clausen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Direct Known Subclasses
Instance Method Summary collapse
- #bad!(pf) ⇒ Object
- #badlist ⇒ Object
- #good!(pf) ⇒ Object
- #goodlist ⇒ Object
-
#initialize(name = "problemfiles") ⇒ CachedResults
constructor
A new instance of CachedResults.
Constructor Details
#initialize(name = "problemfiles") ⇒ CachedResults
Returns a new instance of CachedResults.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/redparse/problemfiles.rb', line 21 def initialize(name="problemfiles") @bad2offset={} @good2offset={} #read list from disk @file=File.open(name,File.exist?(name) ? "r+" : "w+") until @file.eof? at=@file.pos line=@file.readline if line[0]==?# @good2offset[line[1...-1]]=at else @bad2offset[line[1...-1]]=at end end end |
Instance Method Details
#bad!(pf) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/redparse/problemfiles.rb', line 38 def bad! pf @bad2offset[pf] and return self if pos=@good2offset.delete(pf) @bad2offset[pf]=pos @file.pos=pos @file.putc ' ' else @file.seek(0,IO::SEEK_END) @bad2offset[pf]=@file.pos @file.puts " "+pf end @file.flush return self end |
#badlist ⇒ Object
71 72 73 |
# File 'lib/redparse/problemfiles.rb', line 71 def badlist @bad2offset.keys end |
#good!(pf) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/redparse/problemfiles.rb', line 55 def good! pf @good2offset[pf] and return self if offset=@bad2offset.delete(pf) @good2offset[pf]=offset @file.pos=offset @file.putc '#' else @file.seek(0,IO::SEEK_END) @good2offset[pf]=@file.pos @file.puts "#"+pf end @file.flush return pf end |
#goodlist ⇒ Object
75 76 77 |
# File 'lib/redparse/problemfiles.rb', line 75 def goodlist @good2offset.keys end |