From 962c15f7066f9a11e4b6864ccb16872808332776 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Thu, 14 Jul 2022 22:15:38 -0300 Subject: [PATCH] Line -> IO::Line --- bin/json/pull-english | 4 ++-- binlib/{ => io}/line.rb | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) rename binlib/{ => io}/line.rb (52%) diff --git a/bin/json/pull-english b/bin/json/pull-english index d38c9a7..729528c 100755 --- a/bin/json/pull-english +++ b/bin/json/pull-english @@ -14,7 +14,7 @@ require "net/http" require "nokogiri" require "json" require "paint" -require_relative "../../binlib/line" +require_relative "../../binlib/io/line" ## # Configuration variables. @@ -24,7 +24,7 @@ delay = 1.5 ## # Utils -line = Line.new($stdout) +line = IO::Line.new($stdout) find_content = ->(res) do html = Nokogiri::HTML(res.body) el = html.css("div[class^='TranslationText']").last diff --git a/binlib/line.rb b/binlib/io/line.rb similarity index 52% rename from binlib/line.rb rename to binlib/io/line.rb index 35d0302..782f959 100644 --- a/binlib/line.rb +++ b/binlib/io/line.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Line +class IO::Line def initialize(io) @io = io @size = 0 @@ -11,19 +11,18 @@ class Line end def print(str) - str = str.gsub(/\n*/, "") - @size = str.size - @io.print str - self + tap do + str = str.gsub(/\n*/, "") + @size = str.size + @io.print(str) + end end def end - @io.print "\n" - self + tap { @io.print "\n" } end def rewind - @io.print "\b \b" * @size - self + tap { @io.print "\b \b" * @size } end end