Class: Greentext::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/greentext/post.rb

Overview

Public: (Model) A 4chan post in a thread.

Instance Attribute Summary collapse

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

attr_epoch, attr_predicate, attr_reader, #initialize

Constructor Details

This class inherits a constructor from Greentext::Base

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



8
9
10
# File 'lib/greentext/post.rb', line 8

def board
  @board
end

#capcode_repliesObject (readonly)

Returns the value of attribute capcode_replies.



25
26
27
# File 'lib/greentext/post.rb', line 25

def capcode_replies
  @capcode_replies
end

#comObject (readonly)

Returns the value of attribute com.



19
20
21
# File 'lib/greentext/post.rb', line 19

def com
  @com
end

#commentObject (readonly)

Returns the value of attribute comment.



19
20
21
# File 'lib/greentext/post.rb', line 19

def comment
  @comment
end

#countryObject (readonly)

Returns the value of attribute country.



15
16
17
# File 'lib/greentext/post.rb', line 15

def country
  @country
end

#country_nameObject (readonly)

Returns the value of attribute country_name.



16
17
18
# File 'lib/greentext/post.rb', line 16

def country_name
  @country_name
end

#custom_spoilerObject (readonly)

Returns the value of attribute custom_spoiler.



20
21
22
# File 'lib/greentext/post.rb', line 20

def custom_spoiler
  @custom_spoiler
end

#emailObject (readonly)

Returns the value of attribute email.



17
18
19
# File 'lib/greentext/post.rb', line 17

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/greentext/post.rb', line 14

def id
  @id
end

#imagesObject (readonly)

Returns the value of attribute images.



24
25
26
# File 'lib/greentext/post.rb', line 24

def images
  @images
end

#noObject (readonly)

Returns the value of attribute no.



6
7
8
# File 'lib/greentext/post.rb', line 6

def no
  @no
end

#omitted_imagesObject (readonly)

Returns the value of attribute omitted_images.



22
23
24
# File 'lib/greentext/post.rb', line 22

def omitted_images
  @omitted_images
end

#omitted_postsObject (readonly)

Returns the value of attribute omitted_posts.



21
22
23
# File 'lib/greentext/post.rb', line 21

def omitted_posts
  @omitted_posts
end

#repliesObject (readonly)

Returns the value of attribute replies.



23
24
25
# File 'lib/greentext/post.rb', line 23

def replies
  @replies
end

#restoObject (readonly)

Returns the value of attribute resto.



7
8
9
# File 'lib/greentext/post.rb', line 7

def resto
  @resto
end

#semantic_urlObject (readonly)

Returns the value of attribute semantic_url.



27
28
29
# File 'lib/greentext/post.rb', line 27

def semantic_url
  @semantic_url
end

#subObject (readonly)

Returns the value of attribute sub.



18
19
20
# File 'lib/greentext/post.rb', line 18

def sub
  @sub
end

#subjectObject (readonly)

Returns the value of attribute subject.



18
19
20
# File 'lib/greentext/post.rb', line 18

def subject
  @subject
end

#tagObject (readonly)

Returns the value of attribute tag.



26
27
28
# File 'lib/greentext/post.rb', line 26

def tag
  @tag
end

#tripObject (readonly)

Returns the value of attribute trip.



13
14
15
# File 'lib/greentext/post.rb', line 13

def trip
  @trip
end

Instance Method Details

#expandObject



77
78
79
# File 'lib/greentext/post.rb', line 77

def expand
  Greentext.client.expand(self)
end

#imageObject

Public: Get information about the image attached to the post.

Returns a Hash.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/greentext/post.rb', line 41

def image
  if @attrs["tim"]
    {
      width: @attrs["w"],
      height: @attrs["h"],
      filename: @attrs["tim"],
      md5: @attrs["md5"],
      url: "https://i.4cdn.org/#{@attrs['board'].name}/" \
           "#{@attrs['tim']}#{@attrs['ext']}"
    }
  else
    {}
  end
end

#op?Boolean

Public: Determines if the post is OP.

Returns a Boolean value.

Returns:

  • (Boolean)


73
74
75
# File 'lib/greentext/post.rb', line 73

def op?
  @attrs["resto"] == 0
end

#thumbnailObject

Public: Get information about the thumbnail of the image.

Returns a Hash.



59
60
61
62
63
64
65
66
67
68
# File 'lib/greentext/post.rb', line 59

def thumbnail
  if @attrs["tim"]
    { width: @attrs["tn_w"], height: @attrs["tn_h"],
      url: "https://t.4cdn.org/#{@attrs['board'].name}/" \
           "#{@attrs['tim']}s.jpg" 
    }
  else
    {}
  end
end