Class: Ravelry::Comment

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

Overview

The information used to create ‘Ravelry::Comment` comes from Pattern objects.

You should not create ‘Comment` objects manually; they are all created–and owned by–by a Pattern.

See Pattern for more information about ‘Pattern` objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Comment

Creates new ‘Comment` from Ravelry API Pattern Comment attributes.

All class variables are readonly.



16
17
18
19
20
21
22
23
# File 'lib/ravelry/comment.rb', line 16

def initialize(data)
  @data = data
  @user = Ravelry::User.new
  @user.data = data[:user]
  @highlighted_project = data[:highlighted_project]      
  @html = data[:html]
  @id = data[:id]
end

Instance Attribute Details

#highlighted_projectObject (readonly)

Returns the value of attribute highlighted_project.



10
11
12
# File 'lib/ravelry/comment.rb', line 10

def highlighted_project
  @highlighted_project
end

#htmlObject (readonly)

Returns the value of attribute html.



10
11
12
# File 'lib/ravelry/comment.rb', line 10

def html
  @html
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/ravelry/comment.rb', line 10

def id
  @id
end

#userObject (readonly)

Returns the value of attribute user.



10
11
12
# File 'lib/ravelry/comment.rb', line 10

def user
  @user
end

Instance Method Details

#repliesObject



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

def replies
  @reply_list ||= []
  return @reply_list if @reply_list.any?
  @data[:replies].map do |reply|
    @reply_list << Ravelry::Comment.new(reply)
  end
end