ruby-course-2014's People
ruby-course-2014's Issues
Write tests for ArticleManager class
In spec/unit
create file article_manager_spec.rb
. Add a test for each method of ArticleManager
.
Write tests for Article class
In spec/unit
create file article_spec.rb
. Add a test for each method of Article
.
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.
Complete "trygit" tutorial
Link to the tutorial: link.
MockArticle class
Create a class that will automatically generate articles. Create new file and define MockArticle
class:
MockArticle
should inherit fromArticle
.- 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 callArticle
's initialize method with parameters generated withgenerate_author
,generate_content
andgenerate_title
. Then assign number of likes and dislikes withrandom_number
.
Save artciles from internet to files
Extend previous task to save articles to files. Use code that was written couple lessons ago.
Install and read about nokogiri gem
Complete "tryruby" tutorial
Link to the tutorial: link.
Initial commit
-
Install git on your local machine.
-
Add SSH key to your github account. If you have never used ssh keys, here is a quick guide: link
-
Clone this repository to your local machine.
-
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 executingruby document.rb
-
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".
-
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
. Usepositive_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 mostvotes
. - Add method
include?(pattern)
that returns only those articles that haspattern
in itscontent
. - 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 astring
). 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.
Read about creating new gems
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
andauthor
. If no author is present, simply set it as empty string. - Article has
likes
anddislikes
counters initially set to0
. - Article has a time of creation (instance variable
created_at
set toTime.now
while initializing new article) - We should be able to like and dislike article through public methods
like!
anddislike!
that increases counter by1
. - 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 firstlimit-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 toArticle
. It should simply delegate standardinclude?
tocontent
. - Add method
words
that returns array of words fromcontent
. - 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.
Write tests for MockArticle class
In spec/unit
create file mock_article_spec.rb
. Add a test for each method of MockArticle
.
Read about basic testing tools
Read following wiki page: link.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.