Class: Ayadn::Mark
Instance Method Summary collapse
Instance Method Details
#add(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ayadn/mark.rb', line 9 def add(*args) begin init status = Status.new workers = Workers.new(status) unless args.empty? double = args.dup post_id, convo_title = double.shift, double.join(' ') else status.wrong_arguments exit end Check.new(status).bad_post_id(post_id) if [:force] Settings.global.force = true else post_id = workers.get_real_post_id(post_id) end convo_title = post_id if convo_title == '' api, workers, view = API.new, workers, View.new(status, workers) users, bucket = [], [] view.clear_screen status.info(:connected, "analyzing conversation", :yellow) resp = api.get_convo(post_id, ) stream_object = StreamObject.new(resp) posts = workers.build_posts(stream_object.posts.reverse) posts.each do |post| users << "#{post.original_poster}" post.mentions.each {|mention| users << "#{mention}"} bucket << post end users.uniq! now = Time.now.to_s bookmark = { 'id' => post_id, 'root_id' => bucket[0].id, 'last_id' => bucket.last.id, 'title' => convo_title, 'first_date' => bucket[0].date, 'last_date' => bucket.last.date, 'mark_date' => now[0..18], 'first_poster' => bucket[0].original_poster, 'last_poster' => bucket.last.username, 'users' => users, 'size' => bucket.length, 'url' => bucket[0].canonical_url, 'root_text' => bucket[0].raw_text, 'root_colorized_text' => bucket[0].text } view.clear_screen status.info(:done, "bookmarked conversation:", :green) puts make_entry bookmark Databases.add_bookmark bookmark Logs.rec.info "Added conversation bookmark for post #{bookmark['id']}." status.done rescue => e Errors.global_error({error: e, caller: caller, data: [args]}) end end |
#clear ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ayadn/mark.rb', line 92 def clear begin init status = Status.new status.ask_clear_bookmarks input = STDIN.getch if input == 'y' || input == 'Y' Databases.clear_bookmarks Logs.rec.info "Cleared the bookmarks database." status.done else status.canceled exit end rescue => e Errors.global_error({error: e, caller: caller, data: []}) end end |
#delete(*args) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ayadn/mark.rb', line 115 def delete(*args) begin init status = Status.new workers = Workers.new(status) if args.empty? status.wrong_arguments exit else post_id = args[0] end Check.new(status).bad_post_id(post_id) if [:force] Settings.global.force = true else post_id = workers.get_real_post_id(post_id) end Databases.delete_bookmark post_id status.done rescue => e Errors.global_error({error: e, caller: caller, data: [args]}) end end |
#list ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ayadn/mark.rb', line 72 def list begin init list = Databases.all_bookmarks if [:raw] jj JSON.parse(list.to_json) exit end if list.empty? Status.new.empty_list exit end puts "\n" list.each {|marked| puts make_entry(JSON.parse(marked[1])); puts "\n"} rescue => e Errors.global_error({error: e, caller: caller, data: [args, ]}) end end |
#rename(*args) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/ayadn/mark.rb', line 142 def rename(*args) begin init status = Status.new workers = Workers.new(status) unless args.empty? || args[1].nil? arguments = args.dup post_id = arguments.shift else abort Status.wrong_arguments end Check.new(status).bad_post_id(post_id) if [:force] Settings.global.force = true else post_id = workers.get_real_post_id(post_id) end Databases.rename_bookmark post_id, arguments.join(" ") status.done rescue => e Errors.global_error({error: e, caller: caller, data: [args]}) end end |