require 'rpaste/nopaste/metadata' require 'rpaste/resultset' module RPaste module NoPaste class ResultSet < RPaste::ResultSet # # Selects the metadata with dates in between _start_ and _stop_. # def between_dates(start,stop) self.select { |data| data.date.between?(start,stop) } end # # Selects the metadata with the specified _syntax_. # # results.with_syntax('PHP') # def with_syntax(syntax) self.select { |data| data.syntax == syntax } end # # Selects the metadata containing _description_. # # results.with_description('hello world') # results.with_description(/(form|reg)/) # def with_description(description) if description.kind_of?(Regexp) return self.select { |data| data.description =~ description } else return self.select { |data| data.description.include?(description) } end end # # A symonym for with_description. # def search(desc) with_description(desc) end # # Iterates over the metadata with dates falling in between # _start_ and _stop_, passing each to the given _block_. # def each_between_dates(start,stop,&block) between_dates(start,stop).each(&block) end # # Iterates over the metadata with the matching _syntax_, passing each # to the given _block_. # # results.each_with_syntax('ASM') do |metadata| # puts metadata.description # end # def each_with_syntax(syntax,&block) with_syntax(syntax).each(&block) end # # Iterates over the metadata with the matching _description_, passing # each to the given _block_. # # results.each_with_description('fizz') do |metadata| # puts metadata.author # end # # results.each_with_description(/(fi|bu)zz/) do |metadata| # puts metadata.syntax # end # def each_with_description(description,&block) with_description(description).each(&block) end # # Returns the pastes with dates falling in between _start_ and # _stop_. # def pastes_between_dates(start,stop) pastes_with { |data| data.date.between?(start,stop) } end # # Returns the pastes with the matching _syntax_. # # results.pastes_with_syntax('Javascript') # def pastes_with_syntax(syntax) pastes_with { |data| data.syntax == syntax } end # # Returns the pastes with the matching _description_. # # results.pastes_with_description('error') # results.pastes_with_description(/\d+(\.\d+)+/) # def pastes_with_description(description) if description.kind_of?(Regexp) return pastes_with { |data| data.description =~ description } else return pastes_with { |data| data.description.include?(description) } end end # # Returns the pastes with the matching _text_. # # results.pastes_with_text('strcpy') # results.pastes_with_text(/printf\([^\",]+,/) # def pastes_with_text(text) if text.kind_of?(Regexp) return pastes_with { |data| data.text =~ text } else return pastes_with { |data| data.text.include?(text) } end end # # Iterates over the pastes with dates falling in between _start_ and # _stop_, passing each to the given _block_. # def each_paste_between_dates(start,stop,&block) pastes_between_dates(start,stop).each(&block) end # # Iterates over the pastes with the matching _syntax_, passing each # to the given _block_. # # results.each_paste_with_syntax('Java') do |paste| # puts paste.author # end # def each_paste_with_syntax(syntax,&block) pastes_with_syntax(syntax).each(&block) end # # Itereates over the pastes with the matching _description_, passing # each to the given _block_. # # results.each_paste_with_description('stack') do |paste| # puts paste.text # end # # results.each_paste_with_description(/(weird|odd)/) do |paste| # puts paste.text # end # def each_paste_with_description(description,&block) pastes_with_syntax(description).each(&block) end # # Iterates over the pastes with the matching _text_, passing each to # the given _block_. # # results.each_paste_with_text('$_GET') do |paste| # puts paste.text # end # # results.each_paste_with_text(/goto/) do |paste| # puts paste.author # end # def each_paste_with_text(text,&block) pastes_with_text(text).each(&block) end end end end