-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadItem.rb
More file actions
81 lines (66 loc) · 1.96 KB
/
threadItem.rb
File metadata and controls
81 lines (66 loc) · 1.96 KB
1
2
3
4
5
6
7
8
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
=begin
Model object for a thread
Author: Gunbard
=end
class ThreadItem
attr_accessor :replies, :images, :date, :board, :date_added, :title, :url, :new_posts, :enabled, :display_title, :display_color, :deleted, :last_post, :image_urls
TITLE_MAX_LENGTH = 65
def initialize
@replies = '' # Number of replies in a thread
@images = '' # Number of images in a thread
@date = '' # Date of post (UNIX timestamp)
@board = '' # The board the post is on
@date_added = '' # The date this thread was added
@title = '' # May be thread subject or content snippit
@url = '' # Url of thread
@new_posts = 0 # The number of new posts
@enabled = true # Enabled for update checking
@deleted = false # If thread was deleted
@last_post = '' # Date of last post
@image_urls = [] # List of image urls
end
### Getter overrides
def date
# Format as mm/dd/yy
formatted_date = Time.at(@date).to_datetime
formatted_date.strftime('%m/%d/%y%n%l:%M:%S %p')
end
def date_added_display
# Format as mm/dd/yy
formatted_date = Time.at(@date_added).to_datetime
formatted_date.strftime('%m/%d/%y%n%l:%M:%S %p')
end
def last_post_display
# Format as mm/dd/yy
formatted_date = Time.at(@last_post).to_datetime
formatted_date.strftime('%m/%d/%y%n%l:%M:%S %p')
end
def title
# Truncate long string
short_title = @title
if @title.length > TITLE_MAX_LENGTH
short_title = "#{@title[0, TITLE_MAX_LENGTH - 3]}..."
end
short_title
end
def board
"/#{@board}/"
end
### Public methods
# Returns a title for the listbox
def display_title
if @new_posts > 0
return "(#{@new_posts}) #{title}"
end
title
end
# Returns a (hex) color for the listbox title
def display_color
if @deleted
return '#FF0000' # Red
elsif !@enabled
return '#AAAAAA' # Gray
end
'#000000'
end
end