Sha256: 21dc82637dcdcf614b57312c68eae04d32a075cef4b0759fad3042be50bdb08b

Contents?: true

Size: 1017 Bytes

Versions: 5

Compression:

Stored size: 1017 Bytes

Contents

module SiteChecker
  module IO
    class ContentFromFileSystem

      def initialize(visit_references, root)
        @visit_references = visit_references
        @root = root
      end

      def get(link)
        begin
          location = create_absolute_reference(link.url)
          if link.local_page?
            content = File.open(add_index_html(location)).read
          elsif link.local_image?
            File.open(location)
          elsif @visit_references
            open(link.url)
          end
        rescue Errno::ENOENT => e
          raise "(404 Not Found)"
        rescue => e
          raise "(#{e.message.strip})"
        end
        content
      end

      private
      def add_index_html(path)
        path = $1 if path.match(/(.+)#/)
        path.end_with?(".html") ? path : File.join(path, "index.html")
      end

      def create_absolute_reference(link)
        if !link.eql?(@root)
          File.join(@root, link)
        else
          @root
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
site_checker-0.4.0 lib/site_checker/io/content_from_file_system.rb
site_checker-0.3.0 lib/site_checker/io/content_from_file_system.rb
site_checker-0.2.1 lib/site_checker/io/content_from_file_system.rb
site_checker-0.2.0 lib/site_checker/io/content_from_file_system.rb
site_checker-0.2.0.pre lib/site_checker/io/content_from_file_system.rb