Sha256: 0674f6f2b02019c55ece75a7a3b8e3126e362260653cbfc0d38fb238f1d5773f

Contents?: true

Size: 918 Bytes

Versions: 8

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

require 'addressable'

module Aranha
  class DefaultProcessor
    attr_reader :source_uri, :extra_data

    class << self
      def sanitize_uri(uri)
        return uri if uri.is_a?(Hash)
        unless uri.is_a?(Addressable::URI)
          uri = uri.to_s.gsub(%r{\A/}, 'file:///')
        end
        Addressable::URI.parse(uri)
      end
    end

    def initialize(source_uri, extra_data)
      @source_uri = self.class.sanitize_uri(source_uri)
      @extra_data = extra_data
    end

    def process
      raise 'Implement method process'
    end

    protected

    def target_uri
      source_uri
    end

    def data
      @data ||= parser_class.new(target_uri).data
    end

    def parser_class
      r = self.class.name.gsub('::Processors::', '::Parsers::').constantize
      return r unless is_a?(r)

      raise "Parser can be not the process class: #{r}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aranha-0.12.1 lib/aranha/default_processor.rb
aranha-0.12.0 lib/aranha/default_processor.rb
aranha-0.11.2 lib/aranha/default_processor.rb
aranha-0.11.1 lib/aranha/default_processor.rb
aranha-0.11.0 lib/aranha/default_processor.rb
aranha-0.10.1 lib/aranha/default_processor.rb
aranha-0.10.0 lib/aranha/default_processor.rb
aranha-0.9.1 lib/aranha/default_processor.rb