Sha256: 5e267b0b181c1d6d7aaffec4d4588a91ccb7efcddc5d9972c0bcb954d85b0b6e

Contents?: true

Size: 1015 Bytes

Versions: 4

Compression:

Stored size: 1015 Bytes

Contents

module Censys
  class Document
    #
    # Initializes the document.
    #
    # @param [Hash{String => Object}] attributes
    #
    def initialize(attributes)
      @attributes = attributes
    end

    #
    # Provides arbitrary access to the attributes
    #
    # @param [String] name
    #   The dot-separated field name.
    #
    # @return [Object]
    #
    def [](name)
      keys = name.split(".")
      dig(*keys)
    end

    #
    # Dig attributes
    #
    # @param [Array<String>] keys
    #
    # @return [Object]
    #
    def dig(*keys)
      @attributes.dig(*keys)
    end

    #
    # Tags.
    #
    # @return [Array<String>]
    #
    def tags
      @attributes['tags']
    end

    #
    # Time last updated at.
    #
    # @return [Time]
    #
    def updated_at
      @updated_at ||= Time.parse(@attributes['updated_at'])
    end

    #
    # Additional document metadata.
    #
    # @return [Hash{String => Object}]
    #
    def metadata
      @attributes['metadata']
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
censu-0.1.6 lib/censys/document.rb
censu-0.1.5 lib/censys/document.rb
censu-0.1.4 lib/censys/document.rb
censu-0.1.3 lib/censys/document.rb