From ecf963f3defb1b04946b2d9763c5acade84dd51a Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sun, 20 Oct 2024 19:19:41 -0700 Subject: [PATCH] Update bin/readability to work with Ruby 3.x These changes should be backwards compatible with older Ruby versions according to the docs and testing it on Ruby 2.7. Changes: 1. Use `require_relative` to avoid loading errors. 2. Use `URI.parse(...).read` instead of `open(...).read` - This seems to be backwards compatible with older Ruby versions. - Ex. https://www.rubydoc.info/stdlib/open-uri/2.3.1/OpenURI - The behavior should be identical to what we saw before. - `open(...).read` got deprecated in Ruby 3.0 --- README.md | 2 +- bin/readability | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a11c46a..ff87360 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Example require 'readability' require 'open-uri' - source = open('http://lab.arc90.com/experiments/readability/').read + source = URI.parse('http://lab.arc90.com/experiments/readability/').read puts Readability::Document.new(source).content diff --git a/bin/readability b/bin/readability index 1c5b4dc..b8a7011 100755 --- a/bin/readability +++ b/bin/readability @@ -2,7 +2,7 @@ require 'rubygems' require 'open-uri' require 'optparse' -require File.dirname(__FILE__) + '/../lib/readability' +require_relative '../lib/readability' options = { :debug => false, :images => false } options_parser = OptionParser.new do |opts| @@ -28,7 +28,7 @@ if ARGV.length != 1 exit 1 end -text = open(ARGV.first).read +text = URI.parse(ARGV.first).read params = if options[:images] { :tags => %w[div p img a], :attributes => %w[src href],