Class: RedditKit::Link
- Defined in:
- lib/redditkit/link.rb
Overview
A class representing a link.
Instance Attribute Summary collapse
-
#approved_by ⇒ Object
(also: #approved?)
readonly
The username of the moderator who approved this link, if it has been approved.
-
#author ⇒ Object
readonly
The username of the link’s author.
-
#author_flair_css_class ⇒ Object
readonly
The author’s flair CSS class, if they have flair assigned to them.
-
#author_flair_text ⇒ Object
readonly
The author’s flair text, if they have flair assigned to them.
-
#banned_by ⇒ Object
(also: #banned?)
readonly
The username of the moderator who banned this link, if it was banned.
-
#distinguished ⇒ Object
readonly
The distinguished status of the link.
-
#domain ⇒ Object
readonly
The link’s domain.
-
#edited ⇒ Object
readonly
The time of the link’s most recent edit, or nil if it has never been edited.
-
#hidden ⇒ Object
readonly
Whether the current user has hidden this link.
-
#is_self ⇒ Object
(also: #self_post?)
readonly
Whether the link is a self post.
-
#link_flair_css_class ⇒ Object
readonly
The link’s flair CSS class, if it has flair assigned to it.
-
#link_flair_text ⇒ Object
readonly
The link’s flair text, if it has flair assigned to it.
-
#media ⇒ Object
readonly
A hash containing further information about the link’s media.
-
#media_embed ⇒ Object
readonly
A hash contains details for embedding the content in a web page.
-
#num_comments ⇒ Object
(also: #total_comments)
readonly
The number of comments on the link.
-
#num_reports ⇒ Object
(also: #total_reports)
readonly
The number of reports on the link.
-
#over_18 ⇒ Object
(also: #nsfw?)
readonly
Whether the link has been marked as NSFW.
-
#permalink ⇒ Object
readonly
The link to the post on reddit.
-
#saved ⇒ Object
readonly
Whether the current user has saved this link.
-
#selftext ⇒ Object
(also: #text)
readonly
The text for the link, if it is a self post, in Markdown.
-
#selftext_html ⇒ Object
(also: #text_html)
readonly
The text for the link, if it is a self post, in HTML.
-
#stickied ⇒ Object
(also: #sticky?)
readonly
Whether the link has been marked as sticky.
-
#subreddit ⇒ Object
readonly
The name of the subreddit to which the link was posted.
-
#subreddit_id ⇒ Object
(also: #subreddit_full_name)
readonly
The full name of the subreddit to which the link was posted.
-
#thumbnail ⇒ Object
(also: #thumbnail_url)
readonly
The URL to the thumbnail for the link.
-
#title ⇒ Object
readonly
The title of the link.
-
#url ⇒ Object
readonly
The link’s URL.
-
#visited ⇒ Object
readonly
Whether the link has been visited by the current user.
Attributes inherited from Thing
Attributes inherited from Base
Instance Method Summary collapse
-
#image_link? ⇒ Boolean
Determines whether a link has an image URL.
-
#short_link ⇒ String
Returns the short URL for a link.
-
#showing_link_score? ⇒ Boolean
Determines whether a link is showing its score.
Methods included from Votable
#downvoted?, #downvotes, #score, #upvoted?, #upvotes, #voted?
Methods included from Creatable
Methods inherited from Thing
Methods inherited from Base
Constructor Details
This class inherits a constructor from RedditKit::Base
Instance Attribute Details
#approved_by ⇒ Object (readonly) Also known as: approved?
The username of the moderator who approved this link, if it has been approved.
13 14 15 |
# File 'lib/redditkit/link.rb', line 13 def approved_by @approved_by end |
#author ⇒ Object (readonly)
The username of the link’s author.
16 17 18 |
# File 'lib/redditkit/link.rb', line 16 def @author end |
#author_flair_css_class ⇒ Object (readonly)
The author’s flair CSS class, if they have flair assigned to them.
19 20 21 |
# File 'lib/redditkit/link.rb', line 19 def @author_flair_css_class end |
#author_flair_text ⇒ Object (readonly)
The author’s flair text, if they have flair assigned to them.
22 23 24 |
# File 'lib/redditkit/link.rb', line 22 def @author_flair_text end |
#banned_by ⇒ Object (readonly) Also known as: banned?
The username of the moderator who banned this link, if it was banned.
25 26 27 |
# File 'lib/redditkit/link.rb', line 25 def banned_by @banned_by end |
#distinguished ⇒ Object (readonly)
The distinguished status of the link. This is either ‘yes’, ‘no’, ‘admin’ or ‘special’.
28 29 30 |
# File 'lib/redditkit/link.rb', line 28 def distinguished @distinguished end |
#domain ⇒ Object (readonly)
The link’s domain.
31 32 33 |
# File 'lib/redditkit/link.rb', line 31 def domain @domain end |
#edited ⇒ Object (readonly)
The time of the link’s most recent edit, or nil if it has never been edited.
34 35 36 |
# File 'lib/redditkit/link.rb', line 34 def edited @edited end |
#hidden ⇒ Object (readonly)
Whether the current user has hidden this link.
37 38 39 |
# File 'lib/redditkit/link.rb', line 37 def hidden @hidden end |
#is_self ⇒ Object (readonly) Also known as: self_post?
Whether the link is a self post.
40 41 42 |
# File 'lib/redditkit/link.rb', line 40 def is_self @is_self end |
#link_flair_css_class ⇒ Object (readonly)
The link’s flair CSS class, if it has flair assigned to it.
43 44 45 |
# File 'lib/redditkit/link.rb', line 43 def link_flair_css_class @link_flair_css_class end |
#link_flair_text ⇒ Object (readonly)
The link’s flair text, if it has flair assigned to it.
46 47 48 |
# File 'lib/redditkit/link.rb', line 46 def link_flair_text @link_flair_text end |
#media ⇒ Object (readonly)
A hash containing further information about the link’s media. For example, this could contain details about a YouTube video.
49 50 51 |
# File 'lib/redditkit/link.rb', line 49 def media @media end |
#media_embed ⇒ Object (readonly)
A hash contains details for embedding the content in a web page.
52 53 54 |
# File 'lib/redditkit/link.rb', line 52 def @media_embed end |
#num_comments ⇒ Object (readonly) Also known as: total_comments
The number of comments on the link.
55 56 57 |
# File 'lib/redditkit/link.rb', line 55 def num_comments @num_comments end |
#num_reports ⇒ Object (readonly) Also known as: total_reports
The number of reports on the link.
58 59 60 |
# File 'lib/redditkit/link.rb', line 58 def num_reports @num_reports end |
#over_18 ⇒ Object (readonly) Also known as: nsfw?
Whether the link has been marked as NSFW.
61 62 63 |
# File 'lib/redditkit/link.rb', line 61 def over_18 @over_18 end |
#permalink ⇒ Object (readonly)
The link to the post on reddit.
64 65 66 |
# File 'lib/redditkit/link.rb', line 64 def permalink @permalink end |
#saved ⇒ Object (readonly)
Whether the current user has saved this link.
67 68 69 |
# File 'lib/redditkit/link.rb', line 67 def saved @saved end |
#selftext ⇒ Object (readonly) Also known as: text
The text for the link, if it is a self post, in Markdown.
70 71 72 |
# File 'lib/redditkit/link.rb', line 70 def selftext @selftext end |
#selftext_html ⇒ Object (readonly) Also known as: text_html
The text for the link, if it is a self post, in HTML.
73 74 75 |
# File 'lib/redditkit/link.rb', line 73 def selftext_html @selftext_html end |
#stickied ⇒ Object (readonly) Also known as: sticky?
Whether the link has been marked as sticky.
76 77 78 |
# File 'lib/redditkit/link.rb', line 76 def stickied @stickied end |
#subreddit ⇒ Object (readonly)
The name of the subreddit to which the link was posted.
79 80 81 |
# File 'lib/redditkit/link.rb', line 79 def subreddit @subreddit end |
#subreddit_id ⇒ Object (readonly) Also known as: subreddit_full_name
The full name of the subreddit to which the link was posted.
82 83 84 |
# File 'lib/redditkit/link.rb', line 82 def subreddit_id @subreddit_id end |
#thumbnail ⇒ Object (readonly) Also known as: thumbnail_url
The URL to the thumbnail for the link.
85 86 87 |
# File 'lib/redditkit/link.rb', line 85 def thumbnail @thumbnail end |
#title ⇒ Object (readonly)
The title of the link.
88 89 90 |
# File 'lib/redditkit/link.rb', line 88 def title @title end |
#url ⇒ Object (readonly)
The link’s URL. This will be a link to the post on reddit if the link is a self post.
91 92 93 |
# File 'lib/redditkit/link.rb', line 91 def url @url end |
#visited ⇒ Object (readonly)
Whether the link has been visited by the current user. Requires that the current user have reddit gold.
94 95 96 |
# File 'lib/redditkit/link.rb', line 94 def visited @visited end |
Instance Method Details
#image_link? ⇒ Boolean
Determines whether a link has an image URL.
122 123 124 125 |
# File 'lib/redditkit/link.rb', line 122 def image_link? extensions = %w(.png .jpg .jpeg .gif) extensions.any?{ |extension| url.end_with? extension } end |
#short_link ⇒ String
Returns the short URL for a link.
135 136 137 |
# File 'lib/redditkit/link.rb', line 135 def short_link 'http://redd.it/' << id end |
#showing_link_score? ⇒ Boolean
Determines whether a link is showing its score. reddit doesn’t display scores for links less than two hours old.
111 112 113 114 115 116 117 |
# File 'lib/redditkit/link.rb', line 111 def showing_link_score? current_time = Time.now submission_time = created_at difference = (current_time - submission_time) / 60 / 60 difference >= 2 end |