lolibrarian/nypl-tweetwall

View on GitHub
lib/program.rb

Summary

Maintainability
A
15 mins
Test Coverage
class Program
  include NYPLContentType

  BASE_URI = URI.parse("https://www.nypl.org/events/programs/")
  CONTENT_SELECTOR = '.node-event_program'

  # Extracts a NYPL program ID from the given URL.
  def self.id_from_url(url)
    uri = URI(url)
    return unless uri.host == BASE_URI.host

    matches = uri.path.scan(/\A\/events\/programs\/(.+)/).first
    return if matches.nil?

    matches.first
  end
end