generated from Saancha/ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame.rb
More file actions
25 lines (20 loc) · 683 Bytes
/
game.rb
File metadata and controls
25 lines (20 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require_relative 'item'
require 'date'
class Game < Item
attr_accessor :multiplayer, :last_played_at, :title
def initialize(title, publish_date, last_played_at, multiplayer: true)
super(title, publish_date)
@multiplayer = multiplayer
@last_played_at = DateTime.parse(last_played_at)
end
def can_be_archived?
today = DateTime.now
age_in_days = today - @last_played_at
age_in_years = age_in_days.to_i / 365.25
return true if super && age_in_years > 2
false
end
def to_hash
{ title: @title, publish_date: @publish_date.strftime('%Y-%m-%d'), last_played_at: @last_played_at.strftime('%Y-%m-%d'), multiplayer: @multiplayer }
end
end