Class: Box::Comment

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, data) ⇒ Comment

Create a new comment object for a file.

Parameters:

  • api (Api)

    The Api instance used to generate requests.

  • data (Hash)

    The hash of initial info for this item, like ‘id’ and ‘message’.



24
25
26
27
# File 'lib/box/comment.rb', line 24

def initialize(api, data)
  @api = api
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/box/comment.rb', line 31

def method_missing(sym, *args, &block)
  # TODO: Use symbols instead of strings for keys.
  sym = sym.to_s

  return @data[sym] if @data.key?(sym)

  super
end

Class Method Details

.create(api, comments) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/box/comment.rb', line 3

def self.create(api, comments)
  if comments
    comments = [ comments ] if comments.class == Hash

    comments.collect do |comment|
      sub_comments = comment.delete('reply_comments')

      comment['id'] = comment.delete('comment_id')
      comment['comments'] = self.create(api, sub_comments['item']) if sub_comments

      Comment.new(api, comment)
    end
  else
    Array.new
  end
end

Instance Method Details

#deleteObject



44
45
46
47
48
# File 'lib/box/comment.rb', line 44

def delete
  @api.delete_comment(id)

  true
end

#idObject



29
# File 'lib/box/comment.rb', line 29

def id; @data['id']; end

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/box/comment.rb', line 40

def respond_to?(sym)
  @data.key?(sym.to_s) or super
end