Class: Senkyoshi::StaffInfo

Inherits:
FileResource show all
Defined in:
lib/senkyoshi/models/staff_info.rb

Instance Attribute Summary collapse

Attributes inherited from FileResource

#id

Instance Method Summary collapse

Methods inherited from FileResource

#create_module, from

Methods inherited from Resource

#_find_directories, #_fix_path, #_matches_directory_xid?, #_search_and_replace, #cleanup, #fix_html, get_pre_data, #matches_xid?, #strip_xid

Constructor Details

#initialize(resource_id = nil) ⇒ StaffInfo

Returns a new instance of StaffInfo.



23
24
25
26
# File 'lib/senkyoshi/models/staff_info.rb', line 23

def initialize(resource_id = nil)
  super(resource_id)
  @entries = []
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



21
22
23
# File 'lib/senkyoshi/models/staff_info.rb', line 21

def entries
  @entries
end

#titleObject (readonly)

Returns the value of attribute title.



21
22
23
# File 'lib/senkyoshi/models/staff_info.rb', line 21

def title
  @title
end

Instance Method Details

#append_str(body, str, var) ⇒ Object



70
71
72
# File 'lib/senkyoshi/models/staff_info.rb', line 70

def append_str(body, str, var)
  body << str if var && !var.empty?
end

#canvas_conversion(course, resources) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/senkyoshi/models/staff_info.rb', line 92

def canvas_conversion(course, resources)
  page = CanvasCc::CanvasCC::Models::Page.new
  page.body = fix_html(@entries.join(" "), resources)
  page.identifier = @id
  page.page_name = @title.empty? ? "Contact" : @title

  course.pages << page
  course
end

#construct_body(opts) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/senkyoshi/models/staff_info.rb', line 78

def construct_body(opts)
  body = "<div>"
  append_str body, "<img src=#{opts[:image]}/>", opts[:image]
  append_str body, "<h3>#{opts[:name]}</h3>", opts[:name]
  append_str body, "<p>#{opts[:bio]}</p>", opts[:bio]

  body << "<ul>"
  [:email, :phone, :office_hours, :office_address, :home_page].each do |key|
    append_str body, "<li>#{humanize(key)}: #{opts[key]}</li>", opts[key]
  end
  body << "</ul></div>"
  body
end

#humanize(symbol) ⇒ Object



74
75
76
# File 'lib/senkyoshi/models/staff_info.rb', line 74

def humanize(symbol)
  symbol.to_s.humanize.titleize
end

#iterate_xml(xml, _pre_data) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/senkyoshi/models/staff_info.rb', line 43

def iterate_xml(xml, _pre_data)
  contact = xml.xpath("//CONTACT")
  @id ||= xml.xpath("//STAFFINFO/@id").text || Senkyoshi.create_random_hex
  @title ||= xml.xpath("//STAFFINFO/TITLE/@value").text
  bio = xml.xpath("//BIOGRAPHY/TEXT").text
  name = parse_name(contact)
  email = xml.xpath("//CONTACT/EMAIL/@value").text
  phone = xml.xpath("//CONTACT/PHONE/@value").text
  office_hours = xml.xpath("//OFFICE/HOURS/@value").text
  office_address = xml.xpath("//OFFICE/ADDRESS/@value").text
  home_page = xml.xpath("//HOMEPAGE/@value").text
  image = xml.xpath("//IMAGE/@value").text

  @entries << construct_body(
    bio: bio,
    name: name,
    email: email,
    phone: phone,
    office_hours: office_hours,
    office_address: office_address,
    home_page: home_page,
    image: image,
  )

  self
end

#parse_name(contact) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/senkyoshi/models/staff_info.rb', line 28

def parse_name(contact)
  parts = [
    contact.xpath("./NAME/FORMALTITLE/@value").text,
    contact.xpath("./NAME/GIVEN/@value").text,
    contact.xpath("./NAME/FAMILY/@value").text,
  ]

  resp = ""
  parts.each do |part|
    resp << " " unless resp.empty?
    resp << part unless part.empty?
  end
  resp
end