Sha256: 51835c974396ac87470a9f588ef85df60ab3feedf5cb75654b2251d232dd56bc

Contents?: true

Size: 895 Bytes

Versions: 7

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

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

7 entries across 7 versions & 1 rubygems

Version Path
aranha-0.9.0 lib/aranha/default_processor.rb
aranha-0.8.0 lib/aranha/default_processor.rb
aranha-0.7.1 lib/aranha/default_processor.rb
aranha-0.7.0 lib/aranha/default_processor.rb
aranha-0.6.0 lib/aranha/default_processor.rb
aranha-0.5.0 lib/aranha/default_processor.rb
aranha-0.4.0 lib/aranha/default_processor.rb