Class: Strigil::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/strigil/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Comment

Returns a new instance of Comment.



6
7
8
9
10
11
12
# File 'lib/strigil/comment.rb', line 6

def initialize(params={})
  @author = params[:author]
  @subreddit = params[:subreddit]
  @permalink = params[:permalink]
  @timestamp = Time.parse(params[:timestamp])
  @text = params[:text]
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



4
5
6
# File 'lib/strigil/comment.rb', line 4

def author
  @author
end

Returns the value of attribute permalink.



4
5
6
# File 'lib/strigil/comment.rb', line 4

def permalink
  @permalink
end

#subredditObject (readonly)

Returns the value of attribute subreddit.



4
5
6
# File 'lib/strigil/comment.rb', line 4

def subreddit
  @subreddit
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'lib/strigil/comment.rb', line 4

def text
  @text
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



4
5
6
# File 'lib/strigil/comment.rb', line 4

def timestamp
  @timestamp
end

Instance Method Details

#displayObject



24
25
26
27
28
29
30
31
# File 'lib/strigil/comment.rb', line 24

def display
  %{
    posted by #{author} on /r/#{subreddit}
    #{timestamp} | #{permalink}
    -------------------------------------
    #{text}
  }
end

#to_jsonObject



14
15
16
17
18
19
20
21
22
# File 'lib/strigil/comment.rb', line 14

def to_json
  {
    author: author,
    subreddit: subreddit,
    permalink: permalink,
    timestamp: timestamp,
    text: text
  }.to_json
end