Sha256: 7f33bc4a39cd7950268c92c9022fc9e6c41b1cf2de45c5a77b89de23aca42b26

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Aranha
  module Parsers
    class SourceAddress
      class Base
        acts_as_abstract
        common_constructor :source
        compare_by :source

        # @return [String]
        def content
          raise_abstract_method __method__
        end

        # @return [Addressable::URI]
        def uri
          raise_abstract_method __method__
        end

        # @return [String]
        def url
          uri.to_s
        end

        # @return [Hash]
        def source_as_hash
          source_as_hash? ? source.with_indifferent_access : raise('source is not a Hash')
        end

        # @return [Boolean]
        def source_as_hash?
          source.is_a?(::Hash)
        end

        # @|return [Hash]
        def source_as_uri
          source_as_uri? ? source.to_uri : raise('source is not a URI')
        end

        # @return [Boolean]
        def source_as_uri?
          source.to_uri.scheme.present?
        end

        # @return [Boolean]
        def valid?
          raise_abstract_method __method__
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aranha-parsers-0.24.0 lib/aranha/parsers/source_address/base.rb