March 29 - How to Sort URLs from Markdown into Nested Hashes with Regular Expressions
When it comes to parsing files that contain URLs, a common practice is to have the ability to group URLs by type. In this guide we walk through how to categorize links based on regular expressions.
Guide Tasks
  • Read Tutorial
  • Complete the Exercise

Summary

Parse multiple markdown files and group URLs by keywords.

Exercise Description

Inside of multiple markdown files, you will find three types of URLs:

  • rails.devcamp.com URLs that contain the word campsite in the URL string
  • rails.devcamp.com URLs that don't have the word campsite in the URL string
  • URLs that are not located on rails.devcamp.com

In order to successfully complete this exercise, you will need to ignore all of the non rails.devcamp.com URLs, and then group the other two types of URLs into their own nested hashes. Additionally, the markdown files have headings for each day. Utilize the humanize gem so that each day is its own key.

Example Input

There will be 4 full weeks with this type of formatting.

## Week 1
### Monday
- What we’ll learn today: *Setting up your computer with the right tools is the first step to becoming a great developer.  Setting goals will keep you on course and motivated as you go through this life changing experience.*
- [Code exercise](https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/reversing-words-string)
- Workshop  [Environment Customization](https://rails.devcamp.com/trails/dissecting-rails-5/campsites/environment-customization)
- Workshop  [Running Ruby on your system](https://rails.devcamp.com/ruby-programming/introduction-to-the-ruby-programming-lanuage/how-to-install-ruby-on-a-computer)
- Workshop  Bootcamp goal session
- Lecture   [The Developer Tipping Point](https://www.crondose.com/2016/08/discovering-tipping-point-developers/)
### Tuesday
- What we’ll learn today: *Whether you plan to work as a freelancer or in a dev shop or for a company, planning is key to building out your applications.  We will learn about about tracking systems as we get started on our first app.  We will also be expanding our knowledge of ruby basics and discovering tools that we can use when coding with HTML.*
- [Code exercise](https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/build-currency-converter-ruby)
- Workshop  [App Creation and Project Planning](http://rails.devcamp.com/trails/dissecting-rails-5/campsites/app-creation-project-planning)
- Workshop  [Introduction to Ruby](https://rails.devcamp.com/ruby-programming/introduction-to-the-ruby-programming-lanuage/intro-to-the-ruby-programming-language)
- Workshop  HTML skeleton: [Tools We'll Use in the Course](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/tools), [Structure](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/basic-html-website-structure), [Head tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-head-tag)
### Wednesday
- What we’ll learn today: *Building an application is a step by step process.  Keeping track of those steps is what version control is all about.  Git is a widely used version control system that will aid you in this process.  We will also discover how the ruby console can help you see what your code is outputting. Our HTML time will focus on page organization.*
- [Code exercise](https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/create-array-converter-method-ruby)
- Workshop  [Implementing Version Control](http://rails.devcamp.com/trails/dissecting-rails-5/campsites/implementing-version-control)
- Workshop  [Ruby variables](https://rails.devcamp.com/trails/ruby-programming/campsites/ruby-variables)
- Workshop  HTML tags + links: [Creating Page Components with the Div Tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/creating-page-components-div-tag), [Implementing Inline Components with the Span Tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/implementing-inline-components-span-tag), [Integrate Headings into Web Pages](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-headings), [Using Multi Line Content with Paragraph Tags](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/multi-line-content-paragraph-tags), [Working with HTML Hyperlinks](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-hyperlinks), [Adding PageBreaks with the Horizontal Rule Tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/page-breaks-horizontal-rule-tag), [Integrating Line Breaks into HTML Pages](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/line-breaks-html-pages)
- Lecture   [Staying Sharp as a Developer](https://www.crondose.com/2016/07/stay-sharp-developer/)

Example Output

Day three's (Wednesday's) hash element should look like this:

{
  :guide=>
    [
      "https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/create-array-converter-method-ruby",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/creating-page-components-div-tag",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/implementing-inline-components-span-tag",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-headings",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/multi-line-content-paragraph-tags",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-hyperlinks",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/page-breaks-horizontal-rule-tag",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/line-breaks-html-pages"
    ],
  :campsite=>
    [
      "http://rails.devcamp.com/trails/dissecting-rails-5/campsites/implementing-version-control",
      "https://rails.devcamp.com/trails/ruby-programming/campsites/ruby-variables"
    ]
}

Real World Usage

In real world development scenarios, a common task that you will be asked to complete is to build scripts to automate behavior. This specific exercise was a task I was handed a few days ago by the Devcamp development staff. In this guide you will need to work with: regular expressions, nested hashes, and functional programming.

Test Cases

Code File