> For the complete documentation index, see [llms.txt](https://certil-remy.gitbook.io/learn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://certil-remy.gitbook.io/learn/scraping/untitled-13.md).

# Common Anti-Patterns in CLI Data Gem

[Permalink](https://github.com/learn-co-curriculum/oo-ruby-refactoring-cli-gem/blob/a7f5f94b9d6c55a92f104547876eb0b1c5c7d009/README.md)

#### Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

[Sign up](https://github.com/join?source=prompt-blob-show\&source_repo=learn-co-curriculum%2Foo-ruby-refactoring-cli-gem)

&#x20;67 lines (52 sloc) 2.48 KB

## Common Anti-Patterns in CLI Gem Application

*This video walks through the process of refactoring a CLI Gem fixing common anti-patterns in CLI Gem applications*

### Objectives

1. Define anti-patterns
2. Pinpoint flaws in Gem
3. Zipper Pattern
4. Format user output
5. Decouple scraping functionality
6. Create Instances of our Model/Class

### Video

&#x20;\<iframe width="100%" height="720" src="<https://www.youtube.com/embed/cbMa87oWv08?rel=0&showinfo=0>" frameborder="0" allowfullscreen>\</iframe>

\[MP4]\(Find learn s3 source?)

### Summary

* what do we mean by anti-patterns
* explain our gem functionality
* explain our classes
* find flaws in gem
* bunch of different arrays of data instead of unified objects
* explain zipper pattern
* too many calls to website
* We never instantiate instances of our class
* a ton of scraping methods in our story object
* hard coded maximum number for user input
* using `each` instead of `collect`
* examine app in pry
* fix formatting for output
* build functionality to scrape individual story
  * make it work using our zipper pattern
  * fix undefined method error
  * output scraped story
* move scraping logic to a Scraper class
  * change class methods to instance methods
  * define responsibility of Scraper class
  * scrape individual li tags of stories
  * grab individual attributes of that story with css selectors.
  * use those individual story details info to create a new story instance
* add functionalty to Story class to keep track of all its instances
* test scraper functionality
  * last article causes an error
  * use `rescue` to pinpoint source of error
  * create logic to prevent the error stemming from different tags in final article
* implement our new functionality throughout the app
  * use our new logic to obtain and output the stories in cli class
  * add functionality to scrape individual article
* realize how efficient our app is now that we've utilized Object Orientation
* a story object now has power and convenient methods
* commit and examine github diff post refactor

### Code

[Original Code](https://github.com/aviflombaum/techcrunch_cli/tree/pre-refactor)

[Refactored Code](https://github.com/aviflombaum/techcrunch_cli/tree/post-refactor)

[Diff](https://github.com/aviflombaum/techcrunch_cli/compare/pre-refactor...post-refactor?expand=1)

View [Common Anti-Patterns in CLI Data Gem](https://learn.co/lessons/oo-ruby-refactoring-cli-gem) on Learn.co and start learning to code for free.
