lib/ayadn/workers.rb in ayadn-1.0.13 vs lib/ayadn/workers.rb in ayadn-1.1.0
- old
+ new
@@ -93,24 +93,24 @@
def build_posts(data)
# builds a hash of hashes, each hash is a normalized post with post id as a key
posts = {}
data.each.with_index(1) do |post, index|
- next if Databases.blacklist[post['source']['name']]
+ next if Databases.blacklist[post['source']['name'].downcase]
hashtags = extract_hashtags(post)
@skip = false
hashtags.each do |h|
- if Databases.blacklist[h]
+ if Databases.blacklist[h.downcase]
@skip = true
break
end
end
next if @skip
mentions= []
post['entities']['mentions'].each { |m| mentions << m['name'] }
mentions.each do |m|
- if Databases.blacklist["@" + m]
+ if Databases.blacklist["@" + m.downcase]
@skip = true
break
end
end
next if @skip
@@ -290,17 +290,11 @@
text.scan(/#{reg_sentence}/) do |sentence|
sentence.split(' ').each do |word|
if word =~ /#\w+/
words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
elsif word =~ /@\w+/
- splitted = word.split(/#{reg_split}/) if word =~ /#{reg_split}/
- if splitted
- splitted.each {|d| @str = d if d =~ /@\w+/}
- @str = word if @str.nil?
- else
- @str = word
- end
+ @str = def_str(word, reg_split)
if handles.include?(@str.downcase)
words << word.gsub(/#{reg_mention}/, '@\1'.color(mention_color))
else
words << word
end
@@ -313,9 +307,20 @@
end
sentences.join("\n")
end
private
+
+ def def_str(word, reg_split)
+ splitted = word.split(/#{reg_split}/) if word =~ /#{reg_split}/
+ if splitted
+ splitted.each {|d| @str = d if d =~ /@\w+/}
+ return word if @str.nil?
+ @str
+ else
+ word
+ end
+ end
def init_table
Terminal::Table.new do |t|
t.style = { :width => Settings.options[:formats][:table][:width] }
end