-
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.
Merge pull request #26 from AndreaM2429/feature/itemClass
Feature/item class
- Loading branch information
Showing
4 changed files
with
118 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,20 @@ | ||
name: Linters | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
rubocop: | ||
name: Rubocop | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-ruby@v1 | ||
with: | ||
ruby-version: ">=3.1.x" | ||
- name: Setup Rubocop | ||
run: | | ||
gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ | ||
[ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml | ||
- name: Rubocop Report | ||
run: rubocop --color |
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,52 @@ | ||
AllCops: | ||
NewCops: enable | ||
Exclude: | ||
- "Guardfile" | ||
- "Rakefile" | ||
- "node_modules/**/*" | ||
|
||
DisplayCopNames: true | ||
|
||
Layout/LineLength: | ||
Max: 120 | ||
Metrics/MethodLength: | ||
Max: 20 | ||
Metrics/AbcSize: | ||
Max: 50 | ||
Metrics/ClassLength: | ||
Max: 150 | ||
Metrics/BlockLength: | ||
IgnoredMethods: ['describe'] | ||
Max: 30 | ||
|
||
|
||
Style/Documentation: | ||
Enabled: false | ||
Style/ClassAndModuleChildren: | ||
Enabled: false | ||
Style/EachForSimpleLoop: | ||
Enabled: false | ||
Style/AndOr: | ||
Enabled: false | ||
Style/DefWithParentheses: | ||
Enabled: false | ||
Style/FrozenStringLiteralComment: | ||
EnforcedStyle: never | ||
|
||
Layout/HashAlignment: | ||
EnforcedColonStyle: key | ||
Layout/ExtraSpacing: | ||
AllowForAlignment: false | ||
Layout/MultilineMethodCallIndentation: | ||
Enabled: true | ||
EnforcedStyle: indented | ||
Lint/RaiseException: | ||
Enabled: false | ||
Lint/StructNewOverride: | ||
Enabled: false | ||
Style/HashEachMethods: | ||
Enabled: false | ||
Style/HashTransformKeys: | ||
Enabled: false | ||
Style/HashTransformValues: | ||
Enabled: false |
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 @@ | ||
gem 'rubocop', '>= 1.0', '< 2.0' |
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,45 @@ | ||
require 'date' | ||
|
||
class Item | ||
attr_accessor :publish_date | ||
|
||
def initialize(publish_date, id = nil) | ||
@id = id || Random.rand(1..1000) | ||
@publish_date = publish_date | ||
@archived = false | ||
@genre = [] | ||
@author = [] | ||
@label = [] | ||
end | ||
|
||
def genre=(genre) | ||
@genre = genre | ||
genre.genres.push(self) unless genre.genres.include?(self) | ||
end | ||
|
||
def author=(author) | ||
@author = author | ||
author.authors.push(self) unless author.authors.include?(self) | ||
end | ||
|
||
def label=(label) | ||
@label = label | ||
label.labels.push(self) unless label.labels.include?(self) | ||
end | ||
|
||
def move_to_archived | ||
@archived = true if can_be_archieved? | ||
end | ||
|
||
private | ||
|
||
def can_be_archieved? | ||
publish_date = @publish_date.split('/') | ||
publish_date = Time.new(publish_date[2], publish_date[1], publish_date[0]) | ||
|
||
current_date = Time.now.strftime('%d/%m/%Y').split('/') | ||
current_date = Time.new(current_date[2], current_date[1], current_date[0]) | ||
|
||
((current_date.year - publish_date.year) + ((current_date.month - publish_date.month) / 12)) >= 10 | ||
end | ||
end |