class LinkParser

Attributes

Public Class Methods

new(raw, creds) click to toggle source
# File lib/aavimeodl/AVD.rb, line 16
def initialize(raw, creds)
  unparsed_links = narrow_to_week_section(raw.body.dup, creds.day)
  to_hash(unparsed_links)
end

Private Instance Methods

narrow_to_week_section(body, target) click to toggle source
# File lib/aavimeodl/AVD.rb, line 23
def narrow_to_week_section(body, target)
  links = []

  unless target =~ /all/i
    body.shift until body.first =~ Regexp.new("[^\\[#]#{target}", 'i')
    links << body.shift until body.first =~ /homeworks|additional resources|projects/i
  end

  body = links.select! { |l| l =~ /vimeo/ }
end
to_hash(unparsed_links) click to toggle source
# File lib/aavimeodl/AVD.rb, line 34
def to_hash(unparsed_links)
  @links = Hash.new do |h, k|
    k =~ /(\[.*\]).*(http.*)/
    h["#{h.count + 1}: #{$1}"] = $2
  end

  unparsed_links.each { |unparsed| @links[unparsed] }
end