lib/onebox/helpers.rb in onebox-1.8.22 vs lib/onebox/helpers.rb in onebox-1.8.23

- old
+ new

@@ -4,16 +4,16 @@ class DownloadTooLarge < StandardError; end; def self.symbolize_keys(hash) return {} if hash.nil? - hash.inject({}){|result, (key, value)| + hash.inject({}) do |result, (key, value)| new_key = key.is_a?(String) ? key.to_sym : key new_value = value.is_a?(Hash) ? symbolize_keys(value) : value result[new_key] = new_value result - } + end end def self.clean(html) html.gsub(/<[^>]+>/, ' ').gsub(/\n/, '') end @@ -24,11 +24,11 @@ og = {} doc.css('meta').each do |m| if (m["property"] && m["property"][/^og:(.+)$/i]) || (m["name"] && m["name"][/^og:(.+)$/i]) value = (m["content"] || m["value"]).to_s - og[$1.tr('-:','_').to_sym] ||= value unless Onebox::Helpers::blank?(value) + og[$1.tr('-:', '_').to_sym] ||= value unless Onebox::Helpers::blank?(value) end end # Attempt to retrieve the title from the meta tag title_element = doc.at_css('title') @@ -37,11 +37,11 @@ end og end - def self.fetch_response(location, limit=nil, domain=nil, headers=nil) + def self.fetch_response(location, limit = nil, domain = nil, headers = nil) limit ||= 5 limit = Onebox.options.redirect_limit if limit > Onebox.options.redirect_limit raise Net::HTTPError.new('HTTP redirect too deep', location) if limit == 0 @@ -121,22 +121,22 @@ def self.pretty_filesize(size) conv = [ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB' ]; scale = 1024; - ndx=1 - if( size < 2*(scale**ndx) ) then - return "#{(size)} #{conv[ndx-1]}" + ndx = 1 + if (size < 2 * (scale**ndx)) then + return "#{(size)} #{conv[ndx - 1]}" end - size=size.to_f - [2,3,4,5,6,7].each do |i| - if (size < 2*(scale**i)) then - return "#{'%.2f' % (size/(scale**(i-1)))} #{conv[i-1]}" + size = size.to_f + [2, 3, 4, 5, 6, 7].each do |i| + if (size < 2 * (scale**i)) then + return "#{'%.2f' % (size / (scale**(i - 1)))} #{conv[i - 1]}" end end - ndx=7 - return "#{'%.2f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}" + ndx = 7 + return "#{'%.2f' % (size / (scale**(ndx - 1)))} #{conv[ndx - 1]}" end def self.click_to_scroll_div(width = 690, height = 400) "<div style=\"background:transparent;position:relative;width:#{width}px;height:#{height}px;top:#{height}px;margin-top:-#{height}px;\" onClick=\"style.pointerEvents='none'\"></div>" end @@ -148,10 +148,10 @@ value.respond_to?(:empty?) ? !!value.empty? : !value end end def self.truncate(string, length = 50) - string.size > length ? string[0...(string.rindex(" ", length)||length)] + "..." : string + string.size > length ? string[0...(string.rindex(" ", length) || length)] + "..." : string end def self.title_attr(meta) (meta && !blank?(meta[:title])) ? "title='#{meta[:title]}'" : "" end