# -*- encoding: utf-8 -*- module Aclog module Collector module Helper def format_text(status) text = status[:text] entities = status[:entities].map{|k, v| v.map{|n| n.update(type: k)}}.flatten.sort_by{|entity| entity[:indices].first} result = "" last_index = entities.inject(0) do |last_index, entity| result << text[last_index...entity[:indices].first] case entity[:type] when :urls, :media result << "" when :hashtags result << "" when :user_mentions result << "" when :symbols result << "" end entity[:indices].last end result << text[last_index..-1] result end def format_source(status) if status[:source].include?("(.+?)<\/a>/).flatten "" else # web, txt, .. status[:source] end end private # escape ":" to "\\:". "\\" is in neither Unreserved Characters nor Reserved Characters (RFC3986) def escape_colon(str); str.gsub(":", "\\:") end end end end