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.
14 15 16 |
# File 'lib/redditkit/link.rb', line 14 def approved_by @approved_by end |
#author ⇒ Object (readonly)
The username of the link’s author.
17 18 19 |
# File 'lib/redditkit/link.rb', line 17 def @author end |
#author_flair_css_class ⇒ Object (readonly)
The author’s flair CSS class, if they have flair assigned to them.
20 21 22 |
# File 'lib/redditkit/link.rb', line 20 def @author_flair_css_class end |
#author_flair_text ⇒ Object (readonly)
The author’s flair text, if they have flair assigned to them.
23 24 25 |
# File 'lib/redditkit/link.rb', line 23 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.
26 27 28 |
# File 'lib/redditkit/link.rb', line 26 def banned_by @banned_by end |
#distinguished ⇒ Object (readonly)
The distinguished status of the link. This is either ‘yes’, ‘no’, ‘admin’ or ‘special’.
29 30 31 |
# File 'lib/redditkit/link.rb', line 29 def distinguished @distinguished end |
#domain ⇒ Object (readonly)
The link’s domain.
32 33 34 |
# File 'lib/redditkit/link.rb', line 32 def domain @domain end |
#edited ⇒ Object (readonly)
The time of the link’s most recent edit, or nil if it has never been edited.
35 36 37 |
# File 'lib/redditkit/link.rb', line 35 def edited @edited end |
#hidden ⇒ Object (readonly)
Whether the current user has hidden this link.
38 39 40 |
# File 'lib/redditkit/link.rb', line 38 def hidden @hidden end |
#is_self ⇒ Object (readonly) Also known as: self_post?
Whether the link is a self post.
41 42 43 |
# File 'lib/redditkit/link.rb', line 41 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.
44 45 46 |
# File 'lib/redditkit/link.rb', line 44 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.
47 48 49 |
# File 'lib/redditkit/link.rb', line 47 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.
50 51 52 |
# File 'lib/redditkit/link.rb', line 50 def media @media end |
#media_embed ⇒ Object (readonly)
A hash contains details for embedding the content in a web page.
53 54 55 |
# File 'lib/redditkit/link.rb', line 53 def @media_embed end |
#num_comments ⇒ Object (readonly) Also known as: total_comments
The number of comments on the link.
56 57 58 |
# File 'lib/redditkit/link.rb', line 56 def num_comments @num_comments end |
#num_reports ⇒ Object (readonly) Also known as: total_reports
The number of reports on the link.
59 60 61 |
# File 'lib/redditkit/link.rb', line 59 def num_reports @num_reports end |
#over_18 ⇒ Object (readonly) Also known as: nsfw?
Whether the link has been marked as NSFW.
62 63 64 |
# File 'lib/redditkit/link.rb', line 62 def over_18 @over_18 end |
#permalink ⇒ Object (readonly)
The link to the post on reddit.
65 66 67 |
# File 'lib/redditkit/link.rb', line 65 def permalink @permalink end |
#saved ⇒ Object (readonly)
Whether the current user has saved this link.
68 69 70 |
# File 'lib/redditkit/link.rb', line 68 def saved @saved end |
#selftext ⇒ Object (readonly) Also known as: text
The text for the link, if it is a self post, in Markdown.
71 72 73 |
# File 'lib/redditkit/link.rb', line 71 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.
74 75 76 |
# File 'lib/redditkit/link.rb', line 74 def selftext_html @selftext_html end |
#stickied ⇒ Object (readonly) Also known as: sticky?
Whether the link has been marked as sticky.
77 78 79 |
# File 'lib/redditkit/link.rb', line 77 def stickied @stickied end |
#subreddit ⇒ Object (readonly)
The name of the subreddit to which the link was posted.
80 81 82 |
# File 'lib/redditkit/link.rb', line 80 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.
83 84 85 |
# File 'lib/redditkit/link.rb', line 83 def subreddit_id @subreddit_id end |
#thumbnail ⇒ Object (readonly) Also known as: thumbnail_url
The URL to the thumbnail for the link.
86 87 88 |
# File 'lib/redditkit/link.rb', line 86 def thumbnail @thumbnail end |
#title ⇒ Object (readonly)
The title of the link.
89 90 91 |
# File 'lib/redditkit/link.rb', line 89 def title @title end |
#url ⇒ Object (readonly)
This is HTML decoded as reddit encodes their JSON, meaning links which have parameters will be returned incorrectly.
The link’s URL. This will be a link to the post on reddit if the link is a self post.
92 93 94 |
# File 'lib/redditkit/link.rb', line 92 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.
95 96 97 |
# File 'lib/redditkit/link.rb', line 95 def visited @visited end |
Instance Method Details
#image_link? ⇒ Boolean
Determines whether a link has an image URL.
134 135 136 137 |
# File 'lib/redditkit/link.rb', line 134 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.
147 148 149 |
# File 'lib/redditkit/link.rb', line 147 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.
123 124 125 126 127 128 129 |
# File 'lib/redditkit/link.rb', line 123 def showing_link_score? current_time = Time.now submission_time = created_at difference = (current_time - submission_time) / 60 / 60 difference >= 2 end |