Class: CombineHashtags::Post

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

Overview

Post class for profile content

Constant Summary collapse

@@tags =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post_url, img_url, caption, timestamp) ⇒ Post

Returns a new instance of Post.



12
13
14
15
16
17
18
19
# File 'lib/combine_hashtags/post.rb', line 12

def initialize(post_url, img_url, caption, timestamp)
  @post_url = post_url
  @img_url = img_url
  @caption = caption
  @date = Date.parse(timestamp)
  @tags = []
  extract_tags
end

Instance Attribute Details

#captionObject

Returns the value of attribute caption.



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

def caption
  @caption
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#img_urlObject

Returns the value of attribute img_url.



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

def img_url
  @img_url
end

#post_urlObject

Returns the value of attribute post_url.



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

def post_url
  @post_url
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

Class Method Details



33
34
35
# File 'lib/combine_hashtags/post.rb', line 33

def self.popular
  tags.tally.select { |_, value| value > 3 }
end

.tagsObject

TODO: verify if redundant & remove (added flatten! to instance var ^)



29
30
31
# File 'lib/combine_hashtags/post.rb', line 29

def self.tags
  @@tags.flatten
end

Instance Method Details

#extract_tagsObject



21
22
23
24
25
26
# File 'lib/combine_hashtags/post.rb', line 21

def extract_tags
  @tags << @caption.scan(/#\w*/)
  @tags.flatten!
  @@tags << @tags
  @tags = @tags.join(" ")
end