generated from anagudelogu/ruby-rubocop-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from anagudelogu/decorate-a-class
Decorate a class
- Loading branch information
Showing
5 changed files
with
45 additions
and
1 deletion.
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,14 @@ | ||
require_relative './nameable' | ||
|
||
class BaseDecorator < Nameable | ||
attr_accessor :nameable | ||
|
||
def initialize(nameable) | ||
super() | ||
@nameable = nameable | ||
end | ||
|
||
def correct_name | ||
@nameable.correct_name | ||
end | ||
end |
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,7 @@ | ||
require_relative './base_decorator' | ||
|
||
class CapitalizeDecorator < BaseDecorator | ||
def correct_name | ||
@nameable.correct_name.capitalize | ||
end | ||
end |
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,5 @@ | ||
class Nameable | ||
def correct_name | ||
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'" | ||
end | ||
end |
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
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,11 @@ | ||
require_relative './base_decorator' | ||
|
||
class TrimmerDecorator < BaseDecorator | ||
def correct_name | ||
name = @nameable.correct_name | ||
size = name.size | ||
return name.slice!(0..9) if size > 10 | ||
|
||
name | ||
end | ||
end |