Skip to content

Commit

Permalink
Fix rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenofon Deligiannis committed Apr 18, 2019
1 parent bab317d commit e278c9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
12 changes: 7 additions & 5 deletions lib/truncate_html/html_truncator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
19 changes: 9 additions & 10 deletions truncate_html.gemspec
Original file line number Diff line number Diff line change
@@ -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 = ["[email protected]"]
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 = ['[email protected]']
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'

Expand Down

0 comments on commit e278c9b

Please sign in to comment.