lib/ayadn/workers.rb in ayadn-1.2.8 vs lib/ayadn/workers.rb in ayadn-1.2.9

- old
+ new

@@ -3,22 +3,18 @@ class Workers def build_aliases_list(list) table = init_table table.title = "List of your channel aliases".color(:cyan) + "".color(:white) - list.each do |k,v| - table << ["#{k}".color(:green), "#{v}".color(:red)] - end + list.each {|k,v| table << ["#{k}".color(:green), "#{v}".color(:red)]} table end def build_blacklist_list(list) table = init_table table.title = "Your blacklist".color(:cyan) + "".color(:white) - list.each do |k,v| - table << ["#{v.capitalize}".color(:green), "#{k}".color(:red)] - end + list.each {|k,v| table << ["#{v.capitalize}".color(:green), "#{k}".color(:red)]} table end def build_reposted_list(list, target) table = init_table @@ -42,42 +38,39 @@ return users_list, table end def build_followings_list(list, target) #takes a hash of users with ayadn format table = init_table - if target == "me" - table.title = "List of users you're following".color(:cyan) + "".color(:white) + table.title = if target == "me" + "List of users you're following".color(:cyan) + "".color(:white) else - table.title = "List of users ".color(:cyan) + "#{target}".color(:red) + " is following ".color(:cyan) + "".color(:white) + "List of users ".color(:cyan) + "#{target}".color(:red) + " is following ".color(:cyan) + "".color(:white) end users_list = build_users_array(list) build_users_list(users_list, table) end def build_followers_list(list, target) table = init_table - if target == "me" - table.title = "List of your followers".color(:cyan) + "".color(:white) + table.title = if target == "me" + "List of your followers".color(:cyan) + "".color(:white) else - table.title = "List of users following ".color(:cyan) + "#{target}".color(:red) + "".color(:white) + "List of users following ".color(:cyan) + "#{target}".color(:red) + "".color(:white) end - users_list = build_users_array(list) - build_users_list(users_list, table) + build_users_list(build_users_array(list), table) end def build_muted_list(list) table = init_table table.title = "List of users you muted".color(:cyan) + "".color(:white) - users_list = build_users_array(list) - build_users_list(users_list, table) + build_users_list(build_users_array(list), table) end def build_blocked_list(list) table = init_table table.title = "List of users you blocked".color(:cyan) + "".color(:white) - users_list = build_users_array(list) - build_users_list(users_list, table) + build_users_list(build_users_array(list), table) end def build_users_list(list, table) list.each_with_index do |obj, index| unless obj[:name].nil? @@ -144,17 +137,19 @@ type: post['user']['type'], date: parsed_time(post['created_at']), you_starred: post['you_starred'], source_name: source, source_link: post['source']['link'], - canonical_url: post['canonical_url'] + canonical_url: post['canonical_url'], + tags: hashtags, + links: extract_links(post), + mentions: mentions, + directed_to: mentions.first || false } - values[:tags] = hashtags + values[:checkins], values[:has_checkins] = extract_checkins(post) - values[:links] = extract_links(post) - if post['repost_of'] values[:is_repost] = true values[:repost_of] = post['repost_of']['id'] values[:original_poster] = post['repost_of']['user']['username'] else @@ -192,14 +187,10 @@ values[:num_reposts] = post['num_reposts'] else values[:num_reposts] = 0 end - values[:mentions] = mentions - values[:directed_to] = mentions.first || false - values[:checkins], values[:has_checkins] = extract_checkins(post) - posts[post['id'].to_i] = values end posts end @@ -223,16 +214,18 @@ post['entities']['hashtags'].each { |h| tags << h['name'] } tags end def build_channels(data, options = {}) - channels = [] - data.each { |ch| channels << ch } bucket = [] - puts "Downloading new channels and unknown users ids.\nThis is a one time operation, ids are being recorded in a database.\n\nPlease wait, it could take a while if you have many channels...".color(:cyan) unless options[:channels] + if options[:channels] + puts "Downloading list of channels and their users credentials.\n\nPlease wait, it could take a while if there are many results and users...".color(:cyan) + else + puts "Downloading new channels and unknown users ids.\nThis is a one time operation, ids are being recorded in a database.\n\nPlease wait, it could take a while if you have many channels...".color(:cyan) + end chan = Struct.new(:id, :num_messages, :subscribers, :type, :owner, :annotations, :readers, :editors, :writers, :you_subscribed, :unread, :recent_message_id, :recent_message) - channels.each do |ch| + data.each do |ch| unless ch['writers']['user_ids'].empty? usernames = [] ch['writers']['user_ids'].each do |id| db = Databases.users[id] unless db.nil? @@ -313,43 +306,58 @@ reg_split = '[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]' #reg_tag = '#([A-Za-z0-9_]{1,255})(?![\w+])' reg_tag = '#([[:alpha:]0-9_]{1,255})(?![\w+])' reg_mention = '@([A-Za-z0-9_]{1,20})(?![\w+])' reg_sentence = '^.+[\r\n]*' - handles = Array.new + handles, words, sentences = [], [], [] mentions.each {|username| handles << "@#{username}"} - words = Array.new - sentences = Array.new hashtag_color = Settings.options[:colors][:hashtags] mention_color = Settings.options[:colors][:mentions] text.scan(/#{reg_sentence}/) do |sentence| sentence.split(' ').each do |word| + + word_chars = word.chars + sanitized, word = [], [] + word_chars.each do |ch| + if UnicodeUtils.general_category(ch) == :Other_Symbol + sanitized << "#{ch} " + else + sanitized << ch + end + end + word = sanitized.join + if word =~ /#\w+/ slices = word.split('#') has_h = false slices.each do |tag| - bit = tag.downcase.scan(/[[:alpha:]0-9_]/).join('') - if hashtags.include? bit - has_h = true - end + has_h = true if hashtags.include?(tag.downcase.scan(/[[:alpha:]0-9_]/).join('')) end if has_h == true if slices.length > 1 - word = slices.join('#') - words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color)) + words << slices.join('#').gsub(/#{reg_tag}/, '#\1'.color(hashtag_color)) else words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color)) end else words << word end elsif word =~ /@\w+/ - @str = def_str(word, reg_split) - if handles.include?(@str.downcase) - words << word.gsub(/#{reg_mention}/, '@\1'.color(mention_color)) - else - words << word + enc = [] + warr = word.split(' ') + warr.each do |w| + @str = def_str(w, reg_split) + if handles.include?(@str.downcase) + if warr.length == 1 + enc << w.gsub(/#{reg_mention}/, '@\1'.color(mention_color)) + else + enc << " #{w.gsub(/#{reg_mention}/, '@\1'.color(mention_color))}" + end + else + enc << w + end end + words << enc.join else words << word end end sentences << words.join(' ')