From e278c9b9e8d7330f83916680e4013ca4b44cbc26 Mon Sep 17 00:00:00 2001 From: Xenofon Deligiannis Date: Thu, 18 Apr 2019 10:07:40 +0300 Subject: [PATCH] Fix rubocop warnings --- lib/truncate_html/html_truncator.rb | 12 +++++++----- truncate_html.gemspec | 19 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/truncate_html/html_truncator.rb b/lib/truncate_html/html_truncator.rb index 52b707f..07dd808 100644 --- a/lib/truncate_html/html_truncator.rb +++ b/lib/truncate_html/html_truncator.rb @@ -1,18 +1,20 @@ module TruncateHtml class HtmlTruncator - def initialize(original_html, options = {}) @original_html = original_html length = options[:length] || TruncateHtml.configuration.length @omission = options[:omission] || TruncateHtml.configuration.omission - @word_boundary = (options.has_key?(:word_boundary) ? options[:word_boundary] : TruncateHtml.configuration.word_boundary) + @word_boundary = (options.key?(:word_boundary) ? options[:word_boundary] : TruncateHtml.configuration.word_boundary) @break_token = options[:break_token] || TruncateHtml.configuration.break_token || nil @chars_remaining = length - @omission.length - @open_tags, @closing_tags, @truncated_html = [], [], [''] + @open_tags = [] + @closing_tags = [] + @truncated_html = [''] end def truncate return @omission if @chars_remaining < 0 + @original_html.html_tokens.each do |token| if @chars_remaining <= 0 || truncate_token?(token) close_open_tags @@ -82,7 +84,7 @@ def close_open_tags end def remove_latest_open_tag(close_tag) - (0...@open_tags.length).to_a.reverse.each do |index| + (0...@open_tags.length).to_a.reverse_each do |index| if @open_tags[index].matching_close_tag == close_tag @open_tags.delete_at(index) break @@ -91,7 +93,7 @@ def remove_latest_open_tag(close_tag) end def truncate_token?(token) - @break_token and token == @break_token + @break_token && (token == @break_token) end end end diff --git a/truncate_html.gemspec b/truncate_html.gemspec index 014f0ba..b3e5904 100644 --- a/truncate_html.gemspec +++ b/truncate_html.gemspec @@ -1,19 +1,18 @@ -# -*- encoding: utf-8 -*- -require File.expand_path("../lib/truncate_html/version", __FILE__) +require File.expand_path('lib/truncate_html/version', __dir__) Gem::Specification.new do |s| - s.name = "truncate_html" + s.name = 'truncate_html' s.version = TruncateHtml::VERSION - s.authors = ["Harold Giménez"] - s.email = ["harold.gimenez@gmail.com"] - s.homepage = "https://github.com/hgmnz/truncate_html" - s.summary = %q{Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.} - s.description = %q{Truncates html so you don't have to} + s.authors = ['Harold Giménez'] + s.email = ['harold.gimenez@gmail.com'] + s.homepage = 'https://github.com/hgmnz/truncate_html' + s.summary = "Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags." + s.description = "Truncates html so you don't have to" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } + s.require_paths = ['lib'] s.required_ruby_version = '>= 1.9'