class Kuport::Materials

Attributes

base_url[R]
trs[R]

Public Class Methods

new(page) click to toggle source
# File lib/kuport/materials.rb, line 5
def initialize(page)
  @trs = page.at_css('.portlet_module > table').css('tr')
  trs.shift
  @base_url = page.uri
end

Public Instance Methods

materials() click to toggle source
# File lib/kuport/materials.rb, line 11
def materials
  @materials ||= trs.map{|tr| parse_table_line(tr)}.freeze
end
parse_table_line(tr) click to toggle source
# File lib/kuport/materials.rb, line 15
def parse_table_line(tr)
  tds = tr.css('td')
  {subject: tds[1].text,
   teacher: tds[2].text,
   title:   tds[3].text,
   period:  tds[4].text,
   downloaded: (tds[5].text == 'ダウンロード済み'),
   links:   tds[6].css('li').map{|li| parse_link(li)},}.freeze
end
to_h() click to toggle source
# File lib/kuport/materials.rb, line 30
def to_h
  materials
end
to_json(*a) click to toggle source
# File lib/kuport/materials.rb, line 38
def to_json(*a)
  @materials_json ||= to_h.to_json(*a)
end
to_s() click to toggle source
# File lib/kuport/materials.rb, line 34
def to_s
  @materials_s ||= materials.to_s
end