class Threatinator::Feed

Public Class Methods

new(opts = {}) click to toggle source

@param [Hash] opts Options hash @option opts [String] :provider The name of the provider @option opts [String] :name The name of the feed @option opts [Proc] :parser_block A block that will be called by the

parser each time it processes a record.

@option opts [Proc] :parser_builder A proc that, when called, will

return a brand new instance of a Threatinator::Parser.

@option opts [Proc] :fetcher_builder A proc that, when called, will

return a brand new instance of a Threatinator::Fetcher.

@option opts [Array<Proc>] :filter_builders An array of procs that,

when called, will each return an instance of a filter (something that
responds to :filter?)

@option opts [Array<Proc>] :decoder_builders An array of procs that,

when called, will each return an instance of a Threatinator::Decoder
# File lib/threatinator/feed.rb, line 19
def initialize(opts = {})
  @provider = opts.delete(:provider)
  @name = opts.delete(:name)
  @event_types = opts.delete(:event_types) || [:uknown]
  @parser_block = opts.delete(:parser_block)

  @parser_builder = opts.delete(:parser_builder)
  @fetcher_builder = opts.delete(:fetcher_builder)
  @filter_builders = opts.delete(:filter_builders) || []
  @decoder_builders = opts.delete(:decoder_builders) || []
  validate!
end

Public Instance Methods

decoder_builders() click to toggle source
# File lib/threatinator/feed.rb, line 60
def decoder_builders
  @decoder_builders.dup
end
event_types() click to toggle source
# File lib/threatinator/feed.rb, line 40
def event_types
  @event_types.dup
end
fetcher_builder() click to toggle source
# File lib/threatinator/feed.rb, line 48
def fetcher_builder
  @fetcher_builder
end
filter_builders() click to toggle source
# File lib/threatinator/feed.rb, line 56
def filter_builders
  @filter_builders.dup
end
name() click to toggle source
# File lib/threatinator/feed.rb, line 36
def name
  @name.dup
end
parser_block() click to toggle source
# File lib/threatinator/feed.rb, line 44
def parser_block
  @parser_block
end
parser_builder() click to toggle source
# File lib/threatinator/feed.rb, line 52
def parser_builder
  @parser_builder
end
provider() click to toggle source
# File lib/threatinator/feed.rb, line 32
def provider
  @provider.dup
end
validate!() click to toggle source
# File lib/threatinator/feed.rb, line 64
def validate!
  validate_attribute!(:provider, @provider) { |x| x.kind_of?(::String) }
  validate_attribute!(:name, @name) { |x| x.kind_of?(::String) }
  validate_attribute!(:event_types, @event_types) { |x| x.kind_of?(::Array) }
  validate_attribute!(:parser_block, @parser_block) { |x| x.kind_of?(::Proc) }
  validate_attribute!(:fetcher_builder, @fetcher_builder) { |x| x.kind_of?(::Proc) }
  validate_attribute!(:parser_builder, @parser_builder) { |x| x.kind_of?(::Proc) }
  validate_attribute!(:filter_builders, @filter_builders) do |x|
    x.kind_of?(::Array) &&
      x.all? { |e| e.kind_of?(::Proc) }
  end

  validate_attribute!(:decoder_builders, @decoder_builders) do |x|
    x.kind_of?(::Array) &&
      x.all? { |e| e.kind_of?(::Proc) }
  end
end
validate_attribute!(name, val, &block) click to toggle source
# File lib/threatinator/feed.rb, line 82
def validate_attribute!(name, val, &block)
  unless block.call(val) == true
    raise Threatinator::Exceptions::InvalidAttributeError.new("Invalid attribute (#{name}). Got: #{val.inspect}")
  end
end