Class: LiveJournal::Friend

Inherits:
Object
  • Object
show all
Defined in:
lib/livejournal/friends.rb

Overview

Represents a LiveJournal friend relationship. See LiveJournal::Request::Friends to get an array of these.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFriend

Returns a new instance of Friend.



38
39
40
41
42
43
44
45
# File 'lib/livejournal/friends.rb', line 38

def initialize
  @username = nil
  @fullname = nil
  @background = nil
  @foreground = nil
  @groupmask = nil
  @type = nil
end

Instance Attribute Details

#backgroundObject

as HTML color, like ‘#ff0000’



33
34
35
# File 'lib/livejournal/friends.rb', line 33

def background
  @background
end

#foregroundObject

as HTML color, like ‘#ff0000’



33
34
35
# File 'lib/livejournal/friends.rb', line 33

def foreground
  @foreground
end

#fullnameObject

Returns the value of attribute fullname.



31
32
33
# File 'lib/livejournal/friends.rb', line 31

def fullname
  @fullname
end

#groupmaskObject

bitfield of friend groups this friend is a member of



35
36
37
# File 'lib/livejournal/friends.rb', line 35

def groupmask
  @groupmask
end

#typeObject

friend type. possible values: :community, :news, :syndicated, :shared, :identity, :user



37
38
39
# File 'lib/livejournal/friends.rb', line 37

def type
  @type
end

#usernameObject

Returns the value of attribute username.



31
32
33
# File 'lib/livejournal/friends.rb', line 31

def username
  @username
end

Instance Method Details

#from_request(req) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/livejournal/friends.rb', line 46

def from_request(req)
  @username = req['user']
  @fullname = req['name']
  @foreground = req['fg']
  @background = req['bg']
  @groupmask = req['groupmask']
  @type =
    case req['type']
      when 'community';  :community
      when 'news';       :news
      when 'syndicated'; :syndicated
      when 'shared';     :shared
      when 'identity';   :identity
      when nil;          :user
      else raise LiveJournal::Request::ProtocolException.new(
                   "unknown friend type: #{req['type']}")
    end
  self
end

#to_sObject



65
66
67
# File 'lib/livejournal/friends.rb', line 65

def to_s
  "#{@username}: #{@fullname}"
end