Skip to content

Commit

Permalink
Merge pull request #26 from AndreaM2429/feature/itemClass
Browse files Browse the repository at this point in the history
Feature/item class
  • Loading branch information
CesarHerr authored Sep 11, 2023
2 parents da17479 + 1ce0219 commit 793eb9b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/linters.yml
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
52 changes: 52 additions & 0 deletions .rubocop.yml
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
1 change: 1 addition & 0 deletions gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem 'rubocop', '>= 1.0', '< 2.0'
45 changes: 45 additions & 0 deletions item.rb
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

0 comments on commit 793eb9b

Please sign in to comment.