Class: Rst::User

Inherits:
Object
  • Object
show all
Defined in:
lib/rst/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ User

Returns a new instance of User.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rst/user.rb', line 5

def initialize(params)
  @username    = cleanup_whitespace(params.fetch(:username))
  if @username == ""
    raise Rst::InvalidUser.new("A non-blank username is required.")
  end

  @path        = cleanup_whitespace(params.fetch(:path))
  if @path == ""
    raise Rst::InvalidUser.new("A non-blank user path is required.")
  end

  @full_name   = cleanup_whitespace(params.fetch(:full_name, ""))
  @description = cleanup_whitespace(params.fetch(:description, ""))
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/rst/user.rb', line 3

def description
  @description
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



3
4
5
# File 'lib/rst/user.rb', line 3

def full_name
  @full_name
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/rst/user.rb', line 3

def path
  @path
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/rst/user.rb', line 3

def username
  @username
end

Class Method Details

.parse(li) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/rst/user.rb', line 20

def self.parse(li)
  new(
    :username    => li.css("span.user-text").text,
    :full_name   => li.css("span.user-name").text,
    :description => li.css("span.description").text,
    :path        => li.xpath(".//a[contains(concat(' ', normalize-space(@rel), ' '), ' user ')]/@href").text
  )
end