Class: Vortex::Person
- Inherits:
-
Object
- Object
- Vortex::Person
- Defined in:
- lib/vortex_client/person.rb
Overview
Publish Person presentations on Vortex enabled web servers.
Examples:
person = Vortex::Person.new(:user => 'thomasfl',
:image => '/images/thomasfl.jpg',
:language => :english,
:scientific => true)
:publishedDate => "05.01.2010 12:00")
vortex.publish(person)
Mandatory parameters:
:user => username
:image => path to image ex. '/user
Optional parameters:
:language => :english or :norwegian (defaults)
:scientific => false (default). Get list of publications
:administrative = true (default). Same as :scientific => false
:html => json encoded html. Ex
:url => path to presentation. Ex. '/persons/thomas.html'
:publishedDate => date to be published. Defaults to now. Ex. "05.01.2010 12:00"
:filename => filename ex. 'index.html'
Author: Thomas Flemming, thomasfl(at)usit.uio.no 2010
Instance Attribute Summary collapse
-
#administrative ⇒ Object
Returns the value of attribute administrative.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#html ⇒ Object
Returns the value of attribute html.
-
#image ⇒ Object
Returns the value of attribute image.
-
#language ⇒ Object
Returns the value of attribute language.
-
#publishedDate ⇒ Object
Returns the value of attribute publishedDate.
-
#scientific ⇒ Object
Returns the value of attribute scientific.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #content ⇒ Object
-
#create_html(options) ⇒ Object
Generate html for person presentation.
-
#initialize(options = {}) ⇒ Person
constructor
A new instance of Person.
- #properties ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Person
Returns a new instance of Person.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vortex_client/person.rb', line 36 def initialize(={}) .each{|k,v|send("#{k}=",v)} if(not(@user))then raise Exception.new("missing mandatory parameter :user") end if(not(@image))then raise Exception.new("missing mandatory parameter :image ") end # Set defaults if(@language == nil)then @language = :norwegian end if(@scientific == nil)then @scientific = false end if(@administrative == nil and not(@scientific))then @administrative = true end end |
Instance Attribute Details
#administrative ⇒ Object
Returns the value of attribute administrative.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def administrative @administrative end |
#filename ⇒ Object
Returns the value of attribute filename.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def filename @filename end |
#html ⇒ Object
Returns the value of attribute html.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def html @html end |
#image ⇒ Object
Returns the value of attribute image.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def image @image end |
#language ⇒ Object
Returns the value of attribute language.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def language @language end |
#publishedDate ⇒ Object
Returns the value of attribute publishedDate.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def publishedDate @publishedDate end |
#scientific ⇒ Object
Returns the value of attribute scientific.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def scientific @scientific end |
#url ⇒ Object
Returns the value of attribute url.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
34 35 36 |
# File 'lib/vortex_client/person.rb', line 34 def user @user end |
Instance Method Details
#content ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vortex_client/person.rb', line 73 def content image_path = @image image_path = image_path.sub(/^https?:\/\/[^\/]*/i,'') image_path = File.basename(image_path) if(@html)then html = @html else if(@scientific)then html_template = :scientific else html_template = :administrative end html = create_html(:html_template => html_template, :language => @language) end json = <<EOF { "resourcetype": "person", "properties": { "getExternalPersonInfo": "true", "picture": "#{image_path}", "content": "#{html}", "getExternalScientificInformation": "#{@scientific}", "username": "#{@user}", "getRelatedGroups": "true", "getRelatedProjects": "true" } } EOF return json end |
#create_html(options) ⇒ Object
Generate html for person presentation. Defaults to presentation for administrative employees in norwegian
Examples:
create_html()
create_html(:language => :english, :html_template => :scientific)
create_html(:language => :norwegian, :html_template => :administrative)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/vortex_client/person.rb', line 139 def create_html() if([:html_template] && [:html_template] == :scientific) then if([:language] && [:language] == :english) then html = '<h2>Academic Interests<\/h2>\r\n' + '<p>Add information about academic fields of interest.<\/p>\r\n' + '<h2>Teaching<\/h2>\r\n' + '<ul>\r\n' + ' <li><Link to programme of study/course><\/li>\r\n' + ' <li><Link to programme of study/course><\/li>\r\n' + ' <li>...<\/li>\r\n' + '<\/ul>\r\n' + '<h2>Higher education and employment history<\/h2>\r\n' + '<p>Brief introduction to previous education and employment.<\/p>\r\n' + '<h2>Honoraria<\/h2>\r\n' + '<ul>\r\n' + ' <li><Name of prize and (if applicable) link 1><\/li>\r\n' + ' <li><Name of prize and (if applicable) link 2><\/li>\r\n' + ' <li>...<\/li>\r\n' + '<\/ul>\r\n' + '<h2>Appointments<\/h2>\r\n' + '<ul>\r\n' + ' <li><Title and (if applicable) link 1><\/li>\r\n' + ' <li><Title and (if applicable) link 2><\/li>\r\n' + ' <li>...<\/li>\r\n' + '<\/ul>\r\n' + '<h2>Cooperation<\/h2>\r\n' + '<p> <\/p>' else html = '<h2>Faglige interesser<\/h2>\r\n' + '<p>Her kan du skrive om faglige interesser.<\/p>\r\n' + '<h2>Undervisning<\/h2>\r\n<p>' + '<Lenke til studieprogram/emne> <br />\r\n' + '<Lenke til studieprogram/emne> <br />\r\n...<\/p>\r\n' + '<h2>Bakgrunn<\/h2>\r\n' + '<p>Kort om tidligere arbeidserfaring og utdanning<\/p>\r\n' + '<h2>Priser<\/h2>\r\n' + '<p><Navn og eventuelt lenke til pris 1> <br />\r\n' + '<Navn og eventuelt lenke til pris 2> <br />\r\n' + '...<\/p>\r\n' + '<h2>Verv<\/h2>\r\n<p>' + '<Navn og eventuelt lenke til verv 1> <br />\r\n' + '<Navn og eventuelt lenke til verv 2> <br />\r\n...' + '<\/p>\r\n' + '<h2>Samarbeid<\/h2>\r\n' + '<p> <\/p>' end else if([:language] && [:language] == :english) then html = '<h2>Tasks performed<\/h2>\r\n' + '<p>Add information about job duties, as a short text or a bulleted list:<\/p>' + '\r\n<ul>\r\n' + ' <li><Task 1><\/li>\r\n' + ' <li><Task 1><\/li>\r\n' + ' <li>...<\/li>\r\n' + '<\/ul>\r\n' + '<h2>Background<\/h2>\r\n' + '<p>Add information about previous education and employment.<\/p>' else html = '<h2>Arbeidsområder<\/h2>\r\n' + '<p>Her kan du skrive om arbeidsområder, ' + 'enten som kort tekst eller som listepunkter:</p>' + '\r\n' + '<ul>\r\n' + ' <li><Arbeidsområde 1></li>\r\n' + ' <li><Arbeidsområde 1></li>\r\n' + ' <li>...</li>\r\n' + '</ul>' + '\r\n' + '<h2>Bakgrunn</h2>\r\n' + '<p>Eventuelt kort om tidligere arbeidserfaring og utdanning.</p>' end end return html end |
#properties ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vortex_client/person.rb', line 107 def properties properties = '<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>' + '<d:getcontenttype>application/json</d:getcontenttype>' + '<v:resourceType xmlns:v="vrtx">person</v:resourceType>' if(@publishedDate and @publishedDate != "") if(@publishedDate.kind_of? Time) @publishedDate = @publishedDate.httpdate.to_s end props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>' else time = Time.now.httpdate.to_s properties += '<v:publish-date xmlns:v="vrtx">' + time + '</v:publish-date>' end if(language == :english) then properties += '<v:contentLocale xmlns:v="vrtx">en</v:contentLocale>' else properties += '<v:contentLocale xmlns:v="vrtx">no_NO</v:contentLocale>' end return properties end |
#to_s ⇒ Object
217 218 219 |
# File 'lib/vortex_client/person.rb', line 217 def to_s "#<Vortex::Person "+instance_variables.collect{|var|var+": "+instance_variable_get(var).to_s}.join(",")+">" end |