Skip to content

Commit

Permalink
Update bin/readability to work with Ruby 3.x
Browse files Browse the repository at this point in the history
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
  • Loading branch information
apainintheneck committed Oct 21, 2024
1 parent 8abe36e commit ecf963f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions bin/readability
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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],
Expand Down

0 comments on commit ecf963f

Please sign in to comment.