Class: Rubyku::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyku/message.rb

Overview

This class represents messages within Jaiku. The exact representation of the data will be different, depending on whether or not this message was in response to another message. The properties for a Message object are:

  • id: The unique id Jaiku has assigned to this message.

  • title: The text of the message, or the title of the message if this message is a response.

  • entry_title: The title of the original message (only present for comments)

  • content: The content of this message (only present for comments)

  • pretty_content: The content of this message + HTML formatting (only present for comments)

  • url: The url for this message.

  • created_at: An exact timestamp for this message’s creation time.

  • created_at_relative: A friendly relative timestamp (e.g. ‘14 minutes ago’)

  • user: An instance of Rubyku::User representing the user who posted the message.

  • comment: A boolean property representing whether this message is a comment on another message.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



23
24
25
# File 'lib/rubyku/message.rb', line 23

def content
  @content
end

#created_atObject

Returns the value of attribute created_at.



26
27
28
# File 'lib/rubyku/message.rb', line 26

def created_at
  @created_at
end

#created_at_relativeObject

Returns the value of attribute created_at_relative.



27
28
29
# File 'lib/rubyku/message.rb', line 27

def created_at_relative
  @created_at_relative
end

#entry_titleObject

Returns the value of attribute entry_title.



22
23
24
# File 'lib/rubyku/message.rb', line 22

def entry_title
  @entry_title
end

#idObject

Returns the value of attribute id.



20
21
22
# File 'lib/rubyku/message.rb', line 20

def id
  @id
end

#pretty_contentObject

Returns the value of attribute pretty_content.



24
25
26
# File 'lib/rubyku/message.rb', line 24

def pretty_content
  @pretty_content
end

#titleObject

Returns the value of attribute title.



21
22
23
# File 'lib/rubyku/message.rb', line 21

def title
  @title
end

#urlObject

Returns the value of attribute url.



25
26
27
# File 'lib/rubyku/message.rb', line 25

def url
  @url
end

#userObject

Returns the value of attribute user.



28
29
30
# File 'lib/rubyku/message.rb', line 28

def user
  @user
end

Class Method Details

.build_message_from_json(json) ⇒ Object

Given a hash that represents the JSON data from Jaiku for a message, this method will build and return a Rubyku::Message with those properties.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubyku/message.rb', line 44

def build_message_from_json(json)
  m = Rubyku::Message.new
  #the jaiku json objects look differently depending on
  #whether or not they are in response to another message.
  #if they are a response, the comment_id field will be
  #present rather than the id field. A few other distinctions
  #are captured below.
  unless json['comment_id']
    m.comment= false
    m.id = json['id']
  else
    m.comment= true
    m.id = json['comment_id']        
    m.entry_title = json['entry_title']          
    m.pretty_content = json['pretty_content']          
  end

  m.title = json['title']
  m.content = json['content']
  m.url = json['url']
  m.created_at = DateTime.parse(json['created_at'])
  m.created_at_relative = json['created_at_relative']
  m.user = Rubyku::User.build_user_from_json(json['user'])
  
  m
end

Instance Method Details

#comment=(bool) ⇒ Object

:nodoc:



34
35
36
# File 'lib/rubyku/message.rb', line 34

def comment=(bool) #:nodoc:
  @comment= bool
end

#comment?Boolean

:nodoc:

Returns:

  • (Boolean)


30
31
32
# File 'lib/rubyku/message.rb', line 30

def comment? #:nodoc:
  return @comment
end