Class: Stellar::Members::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/stellar/members.rb

Overview

Information about a member’s photo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(div, course) ⇒ Photo

Creates a Stellar client scoped to a student’s Gradebook page.

Parameters:

  • div (Nokogiri::XML::Element)

    a <div> representing a member’s photo and info in the Members Photo page

  • course (Stellar::Course)

    Stellar client scoped to the course that this student belongs to



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/stellar/members.rb', line 119

def initialize(div, course)
  @course = course
  @client = course.client

  unless img = div.css('img[src*="pictures"]').first
    raise ArgumentError, 'Invalid photo-listing <div>'
  end
  @url = URI.join div.document.url, img['src'].gsub('/half/', '/full/') 
  unless mail_link = div.css('a[href*="mailto"]').first
    raise ArgumentError, 'Invalid photo-listing <div>'
  end
  @email = mail_link['href'].sub(/^mailto\:/, '')
  @name = mail_link.inner_text
end

Instance Attribute Details

#clientObject (readonly)

Generic Stellar client used to make requests.



111
112
113
# File 'lib/stellar/members.rb', line 111

def client
  @client
end

#courseObject (readonly)

The course this member belongs to.



108
109
110
# File 'lib/stellar/members.rb', line 108

def course
  @course
end

#emailObject (readonly)

The member’s e-mail.



102
103
104
# File 'lib/stellar/members.rb', line 102

def email
  @email
end

#nameObject (readonly)

The member’s full name.



99
100
101
# File 'lib/stellar/members.rb', line 99

def name
  @name
end

#urlObject (readonly)

URL of the member’s photo.



105
106
107
# File 'lib/stellar/members.rb', line 105

def url
  @url
end

Instance Method Details

#dataObject

The member’s photo bits.



135
136
137
# File 'lib/stellar/members.rb', line 135

def data
  @client.get_file @url
end