class Threatinator::FeedBuilder
Public Class Methods
from_dsl(&block)
click to toggle source
Executes the block parameter within DSL scope
# File lib/threatinator/feed_builder.rb, line 151 def self.from_dsl(&block) Docile.dsl_eval(self.new, &block) end
from_file(filename)
click to toggle source
Loads the provided file, and generates a builder from it. @param [String] filename The name of the file to read the feed from @raise [FeedFileNotFoundError] if the file is not found
# File lib/threatinator/feed_builder.rb, line 122 def self.from_file(filename) begin filedata = File.read(filename) rescue Errno::ENOENT raise Threatinator::Exceptions::FeedFileNotFoundError.new(filename) end from_string(filedata, filename, 0) end
from_string(str, filename = nil, lineno = nil)
click to toggle source
Generates a builder from a string via eval. @param [String] str The DSL code that specifies the feed. @param [String] filename (nil) Passed to eval. @param [String] lineno (nil) Passed to eval. @raise [FeedFileNotFoundError] if the file is not found @see Kernel#eval for details on filename and lineno
# File lib/threatinator/feed_builder.rb, line 137 def self.from_string(str, filename = nil, lineno = nil) from_dsl do args = [str, binding] unless filename.nil? args << filename unless lineno.nil? args << lineno end end eval(*args) end end
Public Instance Methods
build()
click to toggle source
# File lib/threatinator/feed_builder.rb, line 107 def build Feed.new( :provider => @provider, :name => @name, :parser_block => @parser_block, :fetcher_builder => @fetcher_builder, :parser_builder => @parser_builder, :filter_builders => @filter_builders, :decoder_builders => decoder_builders ) end
decode_gzip()
click to toggle source
Add the Gzip decoder
# File lib/threatinator/feed_builder.rb, line 95 def decode_gzip decoder_builders << lambda { Threatinator::Decoders::Gzip.new } self end
Also aliased as: extract_gzip, gunzip
fetch_http(url, opts = {})
click to toggle source
# File lib/threatinator/feed_builder.rb, line 26 def fetch_http(url, opts = {}) opts[:url] = url @fetcher_builder = lambda do opts_dup = Marshal.load(Marshal.dump(opts)) Threatinator::Fetchers::Http.new(opts_dup) end self end
filter(&block)
click to toggle source
Specify a block filter for the parser
# File lib/threatinator/feed_builder.rb, line 74 def filter(&block) @filter_builders ||= [] @filter_builders << lambda { Threatinator::Filters::Block.new(block) } self end
filter_comments()
click to toggle source
Filter
out whitespace lines. Only works on line-based text.
# File lib/threatinator/feed_builder.rb, line 88 def filter_comments @filter_builders ||= [] @filter_builders << lambda { Threatinator::Filters::Comments.new } self end
filter_whitespace()
click to toggle source
Filter
out whitespace lines. Only works on line-based text.
# File lib/threatinator/feed_builder.rb, line 81 def filter_whitespace @filter_builders ||= [] @filter_builders << lambda { Threatinator::Filters::Whitespace.new } self end
name(name)
click to toggle source
# File lib/threatinator/feed_builder.rb, line 21 def name(name) @name = name self end
parse_csv(opts = {}, &block)
click to toggle source
# File lib/threatinator/feed_builder.rb, line 64 def parse_csv(opts = {}, &block) @parser_builder = lambda do opts_dup = Marshal.load(Marshal.dump(opts)) Threatinator::Parsers::CSV::Parser.new(opts_dup, &block) end @parser_block = block self end
parse_eachline(opts = {}, &block)
click to toggle source
# File lib/threatinator/feed_builder.rb, line 55 def parse_eachline(opts = {}, &block) @parser_builder = lambda do opts_dup = Marshal.load(Marshal.dump(opts)) Threatinator::Parsers::Getline::Parser.new(opts_dup, &block) end @parser_block = block self end
parse_json(opts = {}, &block)
click to toggle source
# File lib/threatinator/feed_builder.rb, line 46 def parse_json(opts = {}, &block) @parser_builder = lambda do opts_dup = Marshal.load(Marshal.dump(opts)) Threatinator::Parsers::JSON::Parser.new(opts_dup, &block) end @parser_block = block self end
parse_xml(pattern_string, opts = {}, &block)
click to toggle source
# File lib/threatinator/feed_builder.rb, line 35 def parse_xml(pattern_string, opts = {}, &block) @parser_builder = lambda do pattern = Threatinator::Parsers::XML::Pattern.new(pattern_string) opts_dup = Marshal.load(Marshal.dump(opts)) opts_dup[:pattern] = pattern Threatinator::Parsers::XML::Parser.new(opts_dup, &block) end @parser_block = block self end
provider(provider_name)
click to toggle source
# File lib/threatinator/feed_builder.rb, line 16 def provider(provider_name) @provider = provider_name self end
Private Instance Methods
decoder_builders()
click to toggle source
# File lib/threatinator/feed_builder.rb, line 102 def decoder_builders @decoder_builders ||= [] end