lib/ayadn/view.rb in ayadn-0.6.4 vs lib/ayadn/view.rb in ayadn-1.0.0

- old
+ new

@@ -1,270 +1,507 @@ -#!/usr/bin/env ruby # encoding: utf-8 -class AyaDN - class View - def initialize(hash) - @hash = hash - end - def getData(hash) - hash['data'].reverse - end - def getDataNormal(hash) - hash['data'] - end - def showMessagesFromChannel - buildMessages(getData(@hash)) - end - def showStream - $tools.config['timeline']['downside'] ? the_hash = getData(@hash) : the_hash = getDataNormal(@hash) - buildStream(the_hash) - end - def showCompleteStream - $tools.config['timeline']['downside'] ? the_hash = getData(@hash) : the_hash = getDataNormal(@hash) - stream, pagination_array = buildCompleteStream(the_hash) - end - def show_pm_channels - stream, pagination_array = build_pm_channels_infos - end - def show_channels - stream, pagination_array = build_channels_infos - end - def showDebugStream - begin - puts "\n" - jj getDataNormal(@hash) - rescue => e - puts "\n" - jj @hash - puts e.inspect - end - end - def showUsersList - buildUsersList(getDataNormal(@hash)) - end - def showInteractions - buildInteractions(getData(@hash)) - end - def showUsers - users = "" - @hash = @hash.sort_by {|id, arr| arr[0]} - @hash.each do |id, arr| - users << "#{arr[0]} ".red.ljust(30) + "#{arr[1]}\n".green - end - return users, @hash.length - end - def showUsersInfos(name) - buildUserInfos(name, getDataNormal(@hash)) - end - def showPostInfos(post_id, is_mine) - buildPostInfo(getDataNormal(@hash), is_mine) - end - def showFileInfo(with_url) - buildFileInfo(getDataNormal(@hash), with_url) - end - def buildStream(post_hash) - post_string = "\n" - post_string << post_hash.map {|item| create_content_string(item, nil, false)} - return post_string - end - def buildMessages(messages_stream) - messages_string = "\n" - for item in messages_stream do - @source_name_and_link = objectSource(item) - messages_string << create_content_string(item, checkins_annotations(item), false) # create_content_string(item, annotations, me_mentioned) - end - last_viewed = messages_stream.last - last_id = last_viewed['pagination_id'] unless last_viewed == nil - return messages_string, last_id - end - def buildCompleteStream(post_hash) - post_string = "" - pagination_array = [] - saved_tags = [] - if $tools.config['skipped']['hashtags'] != nil - saved_tags = $tools.config['skipped']['hashtags'].map {|tag| tag.downcase} - end - for item in post_hash do - pagination_array.push(item['pagination_id']) - next if item['text'] == nil - @source_name_and_link = objectSource(item) - case @source_name_and_link[:name] - when *$tools.config['skipped']['sources'] - next - end - next if skip_hashtags(item, saved_tags) - postMentionsArray = [] - @skipped_mentions_encountered = false - for mention in item['entities']['mentions'] do - case mention['name'] - when *$tools.config['skipped']['mentions'] - @skipped_mentions_encountered = true - next - end - postMentionsArray.push(mention['name']) - end - next if @skipped_mentions_encountered - me_mentioned = false - for name in postMentionsArray do - if name == ($tools.config['identity']['prefix'] || $files.users_read("me")) - me_mentioned = true - end - end - post_string << create_content_string(item, checkins_annotations(item), me_mentioned) - end - return post_string, pagination_array - end - def buildSimplePost(post_hash) - create_content_string(post_hash, nil, false) - end - def buildSimplePostInfo(post_hash) - #the_post_id = post_hash['id'] - post_text = post_hash['text'] - post_URL = post_hash['canonical_url'] - post_details = "\nPost URL: ".cyan + post_URL.brown + "\n" - is_reply = post_hash['reply_to'] - post_details << ("This post is a reply to post ".cyan + is_reply.brown + "\n") if is_reply != nil - if post_text != nil - without_braces = $tools.withoutSquareBraces($tools.getMarkdownText(post_text.dup)) - post_details << "\nLength: ".cyan + without_braces.length.to_s.reddish - end - return post_details + "\n\n" - end - def buildPostInfo(post_hash, is_mine) - post_text = post_hash['text'] - post_text != nil ? (colored_post = $tools.colorize(post_text)) : (puts "\n--Post deleted--\n\n".red; exit) - params = objectNames(post_hash['user']) - created_day, created_hour = objectDate(post_hash) - post_details = "\n" + created_day.cyan + ' ' + created_hour.cyan + ' ' + params[:user_handle].green - post_details << (" [#{params[:user_real_name]}]".reddish) if !params[:user_real_name].empty? - post_details << " (follows you)".blue if post_hash['user']['follows_you'] - post_details << " (you follow)".blue if post_hash['user']['you_follow'] - unless post_hash['user']['follows_you'] || post_hash['user']['you_follow'] - post_details << " (you don't follow, doesn't follow you)".blue unless params[:user_name] == $tools.config['identity']['prefix'] - end - post_details << "\n" - post_details << "\n" + colored_post + "\n\n" - post_details << "ID: ".cyan + post_hash['id'].to_s.green + "\n" - post_details << objectLinks(post_hash) - post_details << "Post URL: ".cyan + post_hash['canonical_url'].brown - is_reply = post_hash['reply_to'] - repost_of = post_hash['repost_of'] - post_details << ("\nThis post is a reply to post ".cyan + is_reply.brown) if is_reply != nil - if is_mine == false - if repost_of != nil - post_details << "\nThis post is a repost of post ".cyan + repost_of['id'].brown - else - post_details << "\nReplies: ".cyan + post_hash['num_replies'].to_s.reddish - post_details << " Reposts: ".cyan + post_hash['num_reposts'].to_s.reddish - post_details << " Stars: ".cyan + post_hash['num_stars'].to_s.reddish - end - post_details << ("\nYou reposted this post.".cyan) if post_hash['you_reposted'] - post_details << ("\nYou starred this post.".cyan) if post_hash['you_starred'] - post_details << "\nPosted with: ".cyan + post_hash['source']['name'].reddish - post_details << " Locale: ".cyan + post_hash['user']['locale'].reddish - post_details << " Timezone: ".cyan + post_hash['user']['timezone'].reddish - else - without_braces = $tools.withoutSquareBraces($tools.getMarkdownText(post_text.dup)) - post_details << "\nLength: ".cyan + without_braces.length.to_s.reddish - end - post_details << "\n\n\n" - end - def buildUsersList(users_hash) - users_string = "\n" - users_hash.each do |item| - param = objectNames(item) - users_string << param[:user_real_name].green + " #{param[:user_handle]}\n".cyan - end - users_string << "\n\n" - end - def buildFollowList - users_hash = {} - @hash['data'].each do |item| - user_handle = "@" + item['username'] - users_hash[item['id']] = [user_handle, item['name']] - end - return users_hash, @hash['meta']['min_id'] - end - def buildFileInfo(resp_hash, with_url) - files_details_hash = filesDetails(resp_hash) - #file_url_expires = resp_hash['url_expires'] - #derived_files = resp_hash['derived_files'] - list_string = file_view(files_details_hash) - if files_details_hash[:file_is_public] - list_string << "\nThis file is ".cyan + "public".blue - file_url = files_details_hash[:file_url] - else - list_string << "\nThis file is ".cyan + "private".red - file_url = resp_hash['url'] - end - if with_url - list_string << "\nURL: ".cyan + file_url - #list_string << derivedFilesDetails(derived_files) - end - list_string << "\n\n" - return list_string, file_url, files_details_hash[:name] - end - def showFilesList(with_url, reverse) - reverse ? resp_hash = getDataNormal(@hash) : resp_hash = getData(@hash) - list_string = "" - file_url = nil - pagination_array = [] - resp_hash.each do |item| - pagination_array.push(item['pagination_id']) - files_details_hash = filesDetails(item) - #file_url_expires = item['url_expires'] - #derived_files = item['derived_files'] - list_string << "\nID: ".cyan + files_details_hash[:id].brown - list_string << file_view(files_details_hash) - if files_details_hash[:file_is_public] - list_string << "\nThis file is ".cyan + "public".blue - list_string << "\nLink: ".cyan + item['url_permanent'].magenta - else - list_string << "\nThis file is ".cyan + "private".red - if with_url - file_url = item['url'] - list_string << "\nURL: ".cyan + file_url.brown - #list_string << derivedFilesDetails(derived_files) - end - end - list_string << "\n" - end - list_string << "\n" - return list_string, file_url, pagination_array - end - def buildUserInfos(name, adn_data) - name_params = objectNames(adn_data) - $files.users_write("me", name_params[:user_name]) if name == "me" - $files.users_write(adn_data['id'], name_params[:user_name]) if $files.users_read(adn_data['id']) == nil - created_at = adn_data['created_at'] - user_show = "\nID: ".cyan.ljust(22) + adn_data['id'].green + "\n" - user_show << ("Name: ".cyan.ljust(21) + name_params[:user_real_name].green + "\n") if name_params[:user_real_name] != nil - adn_data['description'] != nil ? user_descr = adn_data['description']['text'] : user_descr = "No description available.".cyan - user_timezone = adn_data['timezone'] - user_show << ("Timezone: ".cyan.ljust(21) + user_timezone.green + "\n") if user_timezone != nil - locale = adn_data['locale'] - user_show << ("Locale: ".cyan.ljust(21) + locale.green + "\n") if locale != nil - user_show << "Posts: ".cyan.ljust(21) + adn_data['counts']['posts'].to_s.green + "\n" + "Followers: ".cyan.ljust(21) + adn_data['counts']['followers'].to_s.green + "\n" + "Following: ".cyan.ljust(21) + adn_data['counts']['following'].to_s.green + "\n" - user_show << "Web: ".cyan.ljust(21) + "http://".green + adn_data['verified_domain'].green + "\n" if adn_data['verified_domain'] != nil - user_show << "Joined: ".cyan.ljust(21) + created_at[0...10].green + " " + created_at[11...19].green + "\n" - user_show << "\n" - user_show << name_params[:user_handle].brown - if name != "me" - if adn_data['follows_you'] - user_show << " follows you\n".green - else - user_show << " doesn't follow you\n".reddish - end - if adn_data['you_follow'] - user_show << "You follow ".green + name_params[:user_handle].brown + "\n" - else - user_show << "You don't follow ".reddish + name_params[:user_handle].brown + "\n" - end - user_show << ("You muted ".reddish + name_params[:user_handle].brown + "\n") if adn_data['you_muted'] - else - user_show << " => " + "yourself!".brown + "\n" - end - user_show << "\n" - user_show << "Bio: \n\n".cyan + user_descr + "\n\n" - end - end -end \ No newline at end of file +module Ayadn + class View + + def initialize + @workers = Workers.new + end + + def show_posts_with_index(data, options) + posts, view = build_stream_with_index(data, options) + puts view + Databases.save_indexed_posts(posts) + end + + def show_posts(data, options) + puts build_stream_without_index(data, options) + end + + def show_raw(stream) + #puts stream.to_json + jj stream + end + + def show_simple_post(post, options) + view = build_stream_without_index(post, options) + puts view + end + + def show_posted(resp) + show_simple_post([resp['data']], {}) + end + + def show_simple_stream(stream) + puts stream + end + + def show_list_reposted(list, target) + users_list, table = @workers.build_reposted_list(list, target) + puts @workers.build_users_list(users_list, table) + puts "\n" + end + + def show_list_starred(list, target) + users_list, table = @workers.build_starred_list(list, target) + puts @workers.build_users_list(users_list, table) + puts "\n" + end + + def show_list_followings(list, target) + puts @workers.build_followings_list(list, target) + puts "\n" + end + + def show_list_followers(list, target) + puts @workers.build_followers_list(list, target) + puts "\n" + end + + def show_list_muted(list) + puts @workers.build_muted_list(list) + puts "\n" + end + + def show_list_blocked(list) + puts @workers.build_blocked_list(list) + puts "\n" + end + + def show_interactions(stream) + #puts "\n" + puts build_interactions_stream(stream) + end + + def show_files_list(list) + puts build_files_list(list) + end + + def show_settings + table = Terminal::Table.new do |t| + t.style = { :width => Settings.options[:formats][:table][:width] } + t.title = "Current Ayadn settings".color(:cyan) + t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ] + @iter = 0 + Settings.options.each do |k,v| + v.each do |x,y| + t << :separator if @iter >= 1 + unless y.is_a?(Hash) + t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), y.to_s.color(:green) ] + else + y.each do |c| + t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), "#{c[0]} = #{c[1]}".color(:green) ] + end + end + @iter += 1 + end + end + end + puts table + end + + def show_userinfos(content, token) + if content['name'] + view = "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name]) + else + view = "Name\t\t\t".color(:cyan) + "(no name)".color(:red) + end + + view << "\n\nUsername\t\t".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:id]) + + view << "\n\nID\t\t\t".color(:cyan) + content['id'].color(Settings.options[:colors][:username]) + + view << "\n\nURL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.options[:colors][:link]) + + unless content['verified_domain'].nil? + if content['verified_domain'] =~ (/http/ || /https/) + domain = content['verified_domain'] + else + domain = "http://#{content['verified_domain']}" + end + view << "\nVerified domain\t\t".color(:cyan) + domain.color(Settings.options[:colors][:link]) + end + + + view << "\n\nAccount creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(:green) + view << "\n\nTimeZone\t\t".color(:cyan) + content['timezone'].color(:green) + view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(:green) + + view << "\n\nPosts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(:green) + + view << "\n\nFollowing\t\t".color(:cyan) + content['counts']['following'].to_s.color(:green) + view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(:green) + + if content['username'] == Settings.config[:identity][:username] + view << "\n\nStorage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(:red) + view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(:green) + end + + #view << "\nStars\t\t\t".color(:cyan) + content['counts']['stars'].to_s.color(:yellow) + + unless content['username'] == Settings.config[:identity][:username] + if content['you_follow'] + view << "\n\nYou follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username]) + else + view << "\n\nYou don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username]) + end + if content['follows_you'] + view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " follows you".color(:cyan) + else + view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " doesn't follow you".color(:cyan) + end + if content['you_muted'] + view << "\nYou muted " + "@#{content['username']}".color(Settings.options[:colors][:username]) + end + if content['you_blocked'] + view << "\nYou blocked " + "@#{content['username']}".color(Settings.options[:colors][:username]) + end + end + + unless content['annotations'].empty? + view << "\n" + end + content['annotations'].each do |anno| + case anno['type'] + when "net.app.core.directory.blog" + view << "\nBlog\t\t\t".color(:cyan) + "#{anno['value']['url']}".color(Settings.options[:colors][:link]) + when "net.app.core.directory.twitter" + view << "\nTwitter\t\t\t".color(:cyan) + "#{anno['value']['username']}".color(:green) + when "com.appnetizens.userinput.birthday" + view << "\nBirthday\t\t".color(:cyan) + "#{anno['value']['birthday']}".color(:green) + end + end + + + #view << "\n\nAvatar URL\t\t".color(:cyan) + content['avatar_image']['url'] + + if content['description'] + view << "\n\n#{content['description']['text']}\n".color(:magenta) + "\n\n" + end + + puts view + + end + + def show_channels(resp) + view = "" + bucket = @workers.build_channels(resp['data']) + bucket.reverse.each do |ch| + view << "\n" + ch_alias = false + Databases.aliases.each do |k,v| + if v == "#{ch.id}" + ch_alias = k + break + end + end + view << "ID: ".color(:cyan) + view << "#{ch.id}".color(Settings.options[:colors][:id]) + view << "\n" + if ch_alias + view << "Alias: ".color(:cyan) + view << "#{ch_alias}".color(Settings.options[:colors][:username]) + view << "\n" + end + view << "Messages: ".color(:cyan) + view << "#{ch.num_messages}".color(Settings.options[:colors][:symbols]) + view << "\n" + if ch.owner + view << "Owner: ".color(:cyan) + view << "@#{ch.owner['username']}".color(Settings.options[:colors][:username]) + # + (#{ch.owner['name']}) if ch.owner['name'] + view << "\n" + end + view << "Writers: ".color(:cyan) + view << "#{ch.writers}".color(Settings.options[:colors][:name]) + view << "\n" + view << "Type: ".color(:cyan) + view << "#{ch.type}".color(Settings.options[:colors][:id]) + view << "\n" + if ch.type == "net.patter-app.room" + ann = ch.annotations.select {|a| a['type'] == "net.patter-app.settings"} + view << "Name: ".color(:cyan) + view << "#{ann[0]['value']['name']}".color(Settings.options[:colors][:link]) + view << "\n" + view << "Description: ".color(:cyan) + view << "#{ann[0]['value']['blurb']}".color(Settings.options[:colors][:username]) + view << "\n" + ann = ch.annotations.select {|a| a['type'] == "net.app.core.fallback_url"} + view << "URL: ".color(:cyan) + view << "#{ann[0]['value']['url']}".color(Settings.options[:colors][:link]) + view << "\n" + end + if ch.type == "net.app.core.broadcast" + ann = ch.annotations.select {|a| a['type'] == "net.app.core.broadcast.metadata"} + view << "Title: ".color(:cyan) + view << "#{ann[0]['value']['title']}".color(Settings.options[:colors][:link]) + view << "\n" + view << "Description: ".color(:cyan) + view << "#{ann[0]['value']['description']}".color(Settings.options[:colors][:username]) + view << "\n" + ann = ch.annotations.select {|a| a['type'] == "net.app.core.fallback_url"} + view << "URL: ".color(:cyan) + view << "#{ann[0]['value']['url']}".color(Settings.options[:colors][:link]) + view << "\n" + end + unless ch.recent_message.nil? + unless ch.recent_message['text'].nil? + view << "Most recent message (#{Workers.new.parsed_time(ch.recent_message['created_at'])}): ".color(:cyan) + view << "\n" + view << "---\n#{ch.recent_message['text']}\n---" + end + end + if ch.type == "net.paste-app.clips" + ann = ch.recent_message['annotations'].select {|a| a['type'] == "net.paste-app.clip"} + view << "\n\n" + view << ann[0]['value']['content'] + view << "\n" + end + view << "\n\n" + end + view << "\nYour account is currently linked to #{bucket.length} channels.\n\n".color(:green) + puts view + end + + def clear_screen + puts "\e[H\e[2J" + end + + private + + def get_broadcast_alias_from_id(event_id) + al = Databases.get_alias_from_id(event_id) + unless al.nil? + al + else + event_id + end + end + + def build_stream_with_index(data, options) #expects an array + @view = "" + posts = @workers.build_posts(data.reverse) + posts.each do |id,content| + count = "%03d" % content[:count] + if content[:username] == Settings.config[:identity][:username] + @view << count.color(Settings.options[:colors][:index]).inverse + elsif content[:mentions].include?(Settings.config[:identity][:username]) && options[:in_mentions].nil? + @view << count.color(Settings.options[:colors][:mentions]).inverse + else + @view << count.color(Settings.options[:colors][:index]) + end + @view << ": ".color(Settings.options[:colors][:index]) + @view << build_content(content) + end + return posts, @view + end + + def build_stream_without_index(data, options) #expects an array + @view = "" + posts = @workers.build_posts(data.reverse) + posts.each do |id,content| + if content[:username] == Settings.config[:identity][:username] + @view << content[:id].to_s.color(Settings.options[:colors][:id]).inverse + " " + elsif content[:mentions].include?(Settings.config[:identity][:username]) && options[:in_mentions].nil? + @view << content[:id].to_s.color(Settings.options[:colors][:mentions]).inverse + " " + else + @view << content[:id].to_s.color(Settings.options[:colors][:id]) + " " + end + @view << build_content(content) + end + @view + end + + def build_interactions_stream(data) + inter = "" + data.reverse.each do |event| + users_array = [] + inter << "#{@workers.parsed_time(event['event_date'])}".color(Settings.options[:colors][:date]) + inter << " => " + event['users'].each do |u| + users_array << "@" + u['username'] + end + case event['action'] + when "broadcast_subscribe" + broadcast = get_broadcast_alias_from_id(event['objects'][0]['id']) + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "subscribed to your broadcast ".color(:green) + inter << "#{broadcast}".color(:red) + when "broadcast_unsubscribe" + broadcast = get_broadcast_alias_from_id(event['objects'][0]['id']) + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "unsubscribed from your broadcast ".color(:green) + inter << "#{broadcast}".color(:red) + when "follow", "unfollow" + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "#{event['action']}ed you".color(:green) + when "mute", "unmute" + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "#{event['action']}d you".color(:green) + when "star", "unstar" + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "#{event['action']}red post ".color(:green) + inter << "#{event['objects'][0]['id']}".color(:red) + when "repost", "unrepost" + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "#{event['action']}ed post ".color(:green) + inter << "#{event['objects'][0]['id']}".color(:red) + when "reply" + inter << "#{users_array.join(", ")} ".color(:magenta) + inter << "replied to post ".color(:green) + inter << "#{event['objects'][0]['id']}".color(:red) + when "welcome" + inter << "App.net ".color(:cyan) + inter << "welcomed ".color(:green) + inter << "you!".color(:yellow) + end + inter << "\n\n" + end + inter + end + + def build_files_list(list) + data = list.reverse + view = "\n" + data.each do |file| + view << "ID\t\t".color(:cyan) + view << file['id'].color(Settings.options[:colors][:id]) + view << "\n" + view << "Name\t\t".color(:cyan) + view << file['name'].color(Settings.options[:colors][:name]) + view << "\n" + view << "Kind\t\t".color(:cyan) + view << file['kind'].color(Settings.options[:colors][:username]) + view << " (#{file['mime_type']})".color(Settings.options[:colors][:username]) if file['mime_type'] + if file['image_info'] + view << "\n" + view << "Dimensions\t".color(:cyan) + view << "#{file['image_info']['width']} x #{file['image_info']['height']}".color(Settings.options[:colors][:username]) + end + view << "\n" + view << "Size\t\t".color(:cyan) + view << file['size'].to_filesize.color(:yellow) + view << "\n" + view << "Date\t\t".color(:cyan) + view << @workers.parsed_time(file['created_at']).color(:green) + view << "\n" + view << "Source\t\t".color(:cyan) + view << file['source']['name'].color(Settings.options[:colors][:source]) + view << "\n" + view << "State\t\t".color(:cyan) + if file['public'] + view << "Public".color(Settings.options[:colors][:id]) + view << "\n" + view << "Link\t\t".color(:cyan) + view << file['url_short'].color(Settings.options[:colors][:link]) + else + view << "Private".color(Settings.options[:colors][:id]) + end + + view << "\n\n" + end + view + end + + def build_content(content) + view = "" + view << build_header(content) + view << "\n" + view << content[:text] + view << "\n" + if content[:has_checkins] + view << build_checkins(content) + view << "\n" + end + unless content[:links].empty? + view << "\n" + content[:links].each do |link| + view << link.color(Settings.options[:colors][:link]) + view << "\n" + end + end + view << "\n\n" + end + + def build_header(content) + header = "" + header << content[:handle].color(Settings.options[:colors][:username]) + if Settings.options[:timeline][:show_real_name] + header << " " + header << content[:name].color(Settings.options[:colors][:name]) + end + if Settings.options[:timeline][:show_date] + header << " " + header << content[:date].color(Settings.options[:colors][:date]) + end + if Settings.options[:timeline][:show_source] + header << " " + header << "[#{content[:source_name]}]".color(Settings.options[:colors][:source]) + end + if Settings.options[:timeline][:show_symbols] + header << " <".color(Settings.options[:colors][:symbols]) if content[:is_reply] + header << " #{content[:num_stars]}*".color(Settings.options[:colors][:symbols]) if content[:is_starred] + header << " >".color(Settings.options[:colors][:symbols]) if content[:num_replies] > 0 + header << " #{content[:num_reposts]}x".color(Settings.options[:colors][:symbols]) if content[:num_reposts] > 0 + end + header << "\n" + end + + def build_checkins(content) + unless content[:checkins][:name].nil? + num_dots = content[:checkins][:name].length + else + num_dots = 10 + end + hd = (".".color(Settings.options[:colors][:dots])) * num_dots + hd << "\n" + formatted = { header: hd } + content[:checkins].each do |key, val| + formatted[key] = val unless (val.nil? || !val) + end + + chk = formatted[:header] + unless formatted[:name].nil? + chk << formatted[:name].color(Settings.options[:colors][:dots]) + chk << "\n" + end + unless formatted[:address].nil? + chk << formatted[:address] + chk << "\n" + end + unless formatted[:address_extended].nil? + chk << formatted[:address_extended] + chk << "\n" + end + unless formatted[:country_code].nil? + cc = "(#{formatted[:country_code]})".upcase + else + cc = "" + end + unless formatted[:postcode].nil? + unless formatted[:locality].nil? + chk << "#{formatted[:postcode]}, #{formatted[:locality]} #{cc}" + chk << "\n" + end + else + unless formatted[:locality].nil? + chk << "#{formatted[:locality]} #{cc}" + chk << "\n" + end + end + unless formatted[:website].nil? + chk << formatted[:website] + chk << "\n" + end + unless formatted[:telephone].nil? + chk << formatted[:telephone] + chk << "\n" + end + unless formatted[:categories].nil? + chk << formatted[:categories] + chk << "\n" + end + + chk.chomp + end + + end +end