generated from Saancha/ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b75bd6
commit 3586b14
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'date' | ||
|
||
class Item | ||
attr_accessor :publish_date, :archived | ||
attr_reader :genre, :author, :source, :label, :id | ||
|
||
def initialize(publish_date, archived: false) | ||
@id = Random.rand(1...100) | ||
@publish_date = DateTime.parse(publish_date) | ||
@archived = archived | ||
end | ||
|
||
def add_genre(genre_name) | ||
@genre = genre_name | ||
end | ||
|
||
def add_label(label_name) | ||
@label = label_name | ||
end | ||
|
||
def add_author(author_name) | ||
@author = author_name | ||
end | ||
|
||
def add_source(source_name) | ||
@source = source_name | ||
end | ||
|
||
def can_be_archived? | ||
today = DateTime.now | ||
age_in_days = today - @publish_date | ||
age_in_years = age_in_days.to_i / 365.25 | ||
return true if age_in_years >= 10 | ||
false | ||
end | ||
|
||
def move_to_archive | ||
if can_be_archived? | ||
@archived = true | ||
end | ||
end | ||
|
||
end |