Git Product home page Git Product logo

ruby-course-2014's People

Watchers

 avatar  avatar

ruby-course-2014's Issues

Read article from file

Add method to ArticleFilesystem that for given path to file will return Article instance based on contents of the file. You can assume that file has only one line of following format: <author>|<title>|<content>|<likes>|<dislikes>. Do not check if it is correct. Assume that data is always correct. Do not use any exception handling.

MockArticle class

Create a class that will automatically generate articles. Create new file and define MockArticle class:

  • MockArticle should inherit from Article.
  • Add method random_number, that returns random number between 0 and 100)
  • Add constant WORD_LIST that will contain words used in generating article. All methods below should use this list.
  • Add method generate_author that returns random author name (containing two words). Remember that first and last name should be capitalized.
  • Add method generate_title that returns random title (containing from 1 to 5 words). First word should be capitalized.
  • Add method generate_sentence that returns a single sentence (string starting with capitalized word and ending with a dot) containing from 5 to 10 words.
  • Add method generate_content that returns article content. It should contain from 1 to 5 sentences. Don't forget to add space after each sentence (except for the last one).
  • When calling MockArticle.new (initialize method) you should call Article's initialize method with parameters generated with generate_author, generate_content and generate_title. Then assign number of likes and dislikes with random_number.

Initial commit

  1. Install git on your local machine.

  2. Add SSH key to your github account. If you have never used ssh keys, here is a quick guide: link

  3. Clone this repository to your local machine.

  4. In root directory of this repo create file document.rb and add just one line:

    puts Time.now

    If your ruby installed correctly, you should see the current time when executing ruby document.rb

  5. Add this file to repository and make your initial commit with message "initial commit". Don't forget to add number of THIS issue to the commit messege e.g. it may look like "[#1234] initial commit".

  6. Push new commit to github: git push origin master

ArticleManager class

Create new file and define ArticleManager class. Follow the requirements:

  • ArticleManager should contain array of articles
  • Add methods worst_articles, best_articles, worst_article, best_article. Use positive_votes as a measure. First two methods should return sorted arrays of articles. Last two methods should return a single article.
  • Add method most_popular_article which returns article with most votes.
  • Add method include?(pattern) that returns only those articles that has pattern in its content.
  • Add method authors that returns list of authors (distinct).
  • Add method number_of_authors that returns number of different authors
  • Add method votes that returns sum of votes in all articles
  • Overload method to_s that will return nicely formatted list of all articles (you have to return a string). I will leave this to your imagination.

Download articles from internet

Add functionality to our articles system that will allow us to get articles from https://zapisy.ii.uni.wroc.pl/news/ and store them in form of Article instances. The details of this task I leave to your imagination - you can fetch all articles from first page or all articles from a specified page or search for the first article of a given author etc.
You will most likely need to create new file(s) with class(es). All the naming of classes, methods and how they interact is up to you, but remember things you have learned so far.

Write article to file

Create new file with class ArticleFilesystem. All methods in this class will be class methods.
Add constant ARTICLES_FOLDER. It should contain path to some directory. Add method that will take article as a parameter. It should create new file in ARTICLES_FOLDER directory. Name of the file depends on articles title, for example: if article's title is "Crime and Punishment", then new file should be called crime_and_punishment. File itself should contain only one line of the following format:
<author>|<title>|<content>|<likes>|<dislikes>

Load articles to ArticleManager

Add method load_articles (instance method this time) to ArticleManager class that for given path to directory will load all articles (stored in files) from that directory. You must use ArtcileFilesystem's reading method.

Create and use your own gem

In this task you will create a new gem. If you knew basic principles of software engineering you would've noticed that MockArticle has too many responsibilities. First: it serves as a mock for an actual article. This is what we want and that was the intention of creating this class. But it also has a lot of code for generating random strings (sentences, titles etc.). We want to separate string generation from MockArticle.

Create new gem named bla-bla. You have to create NEW repository locally and on github called bla-bla. DO NOT make new gem inside ruby-course-2014. Move methods generate_title, generate_content, generate_author to your new gem (that also includes tests for those methods). In the end, your mock_article.rb file should look more or less like this:

require_relative 'article.rb'
require 'bla-bla'

class MockArticle < Article

  def initialize
    super(BlaBla.title, BlaBla.content, BlaBla.author)
    @likes, @dislikes = random_number, random_number
  end

  def random_number
    rand(101)
  end
end

Post link to new repository in comments to this task when you are finished.

Article class

We are going to create articles management system. First create new file and define Article class. Add methods and instance variables according to requirements:

  • When creating new article you should give it title, content and author. If no author is present, simply set it as empty string.
  • Article has likes and dislikes counters initially set to 0.
  • Article has a time of creation (instance variable created_at set to Time.now while initializing new article)
  • We should be able to like and dislike article through public methods like! and dislike! that increases counter by 1.
  • We should be able to get the number of positive votes (number of likes minus number of diskiles) through public method positive_votes
  • Same for total number of votes (likes + dislikes).
  • We should be able to see shortened form of articles content. Add method shortened_to(limit). This method should return only first limit-3 letters of artilce content concatenated with "...". Example:
  a1 = Article.new("Crime and Punishment","On an exceptionally hot evening early in July a young man came out of the garret","Fyodor Dostoevsky")
  puts a1.shortened_to(22) # prints => "On an exceptionally..."
  • Previous method should simply return content if limit is greater than contents size.
  • See what include? method does in the Ruby documentation and add this method to Article. It should simply delegate standard include? to content.
  • Add method words that returns array of words from content.
  • Add method distinct_words.

Install and use 'stamp' gem

Install gem stamp: https://github.com/jeremyw/stamp

Check README about how to use it. Add method created_stamp to class Article. It should return formatted time based on variable @created_at. Returned string should look like:

 "Sunday, May 1, 2000"

Don't forget to add test for this method.

Prepare testing environment

Create folder spec. All testing code will be put there. Inside spec create folder unit. Also in spec create file run_tests.rb and add following code:

require 'test/unit'

Add code to run_tests.rb that will load/require every file from folder unit that ends with _spec.rb (does not need to include subfolders). Later we want to run all tests by doing simply: ruby spec/run_tests.rb.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.