Class: Vortex::Person

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options={})
  options.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

#administrativeObject

Returns the value of attribute administrative.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def administrative
  @administrative
end

#filenameObject

Returns the value of attribute filename.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def filename
  @filename
end

#htmlObject

Returns the value of attribute html.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def html
  @html
end

#imageObject

Returns the value of attribute image.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def image
  @image
end

#languageObject

Returns the value of attribute language.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def language
  @language
end

#publishedDateObject

Returns the value of attribute publishedDate.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def publishedDate
  @publishedDate
end

#scientificObject

Returns the value of attribute scientific.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def scientific
  @scientific
end

#urlObject

Returns the value of attribute url.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def url
  @url
end

#userObject

Returns the value of attribute user.



34
35
36
# File 'lib/vortex_client/person.rb', line 34

def user
  @user
end

Instance Method Details

#contentObject



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(options)
  if(options[:html_template] && options[:html_template] == :scientific) then

    if(options[:language] && options[: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>&lt;Link to programme of study/course&gt;<\/li>\r\n' +
        '    <li>&lt;Link to programme of study/course&gt;<\/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>&lt;Name of prize and (if applicable) link 1&gt;<\/li>\r\n' +
        '    <li>&lt;Name of prize and (if applicable) link 2&gt;<\/li>\r\n' +
        '    <li>...<\/li>\r\n' +
        '<\/ul>\r\n' +
        '<h2>Appointments<\/h2>\r\n' +
        '<ul>\r\n' +
        '    <li>&lt;Title and (if applicable) link 1&gt;<\/li>\r\n' +
        '    <li>&lt;Title and (if applicable) link 2&gt;<\/li>\r\n' +
        '    <li>...<\/li>\r\n' +
        '<\/ul>\r\n' +
        '<h2>Cooperation<\/h2>\r\n' +
        '<p>&nbsp;<\/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>' +
        '&lt;Lenke til studieprogram/emne&gt; <br />\r\n' +
        '&lt;Lenke til studieprogram/emne&gt; <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>&lt;Navn og eventuelt lenke til pris 1&gt; <br />\r\n'  +
        '&lt;Navn og eventuelt lenke til pris 2&gt; <br />\r\n' +
        '...<\/p>\r\n' +
        '<h2>Verv<\/h2>\r\n<p>' +
        '&lt;Navn og eventuelt lenke til verv 1&gt; <br />\r\n' +
        '&lt;Navn og eventuelt lenke til verv 2&gt; <br />\r\n...' +
        '<\/p>\r\n' +
        '<h2>Samarbeid<\/h2>\r\n' +
        '<p>&nbsp;<\/p>'
    end
  else

    if(options[:language] && options[: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>&lt;Task 1&gt;<\/li>\r\n' +
        '  <li>&lt;Task 1&gt;<\/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&aring;der<\/h2>\r\n' +
        '<p>Her kan du skrive om arbeidsomr&aring;der, ' +
        'enten som kort tekst eller som listepunkter:</p>' +
        '\r\n' +
        '<ul>\r\n' +
        '    <li>&lt;Arbeidsomr&aring;de 1&gt;</li>\r\n' +
        '    <li>&lt;Arbeidsomr&aring;de 1&gt;</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

#propertiesObject



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_sObject



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