Sha256: c9f2e0af873030126bd9739f0d1470297bc872bc708010f2f42f8eca6bd69f46

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true

require "normalize_country"

module Mihari
  module Models
    #
    # Geolocation model
    #
    class Geolocation < ActiveRecord::Base
      belongs_to :artifact

      class << self
        #
        # Build Geolocation
        #
        # @param [String] ip
        # @param [Mihari::Enrichers::MMDB] enricher
        #
        # @return [Mihari::Geolocation, nil]
        #
        def build_by_ip(ip, enricher: Enrichers::MMDB.new)
          enricher.result(ip).fmap do |res|
            if res.country_code
              new(country: NormalizeCountry(res.country_code, to: :short),
                country_code: res.country_code)
            end
          end.value_or nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mihari-7.0.0 lib/mihari/models/geolocation.rb