Class: Skunk::Generator::Html::PathTruncator
- Inherits:
-
Object
- Object
- Skunk::Generator::Html::PathTruncator
- Defined in:
- lib/skunk/generators/html/path_truncator.rb
Overview
Utility class for truncating file paths to show only the relevant project structure
Constant Summary collapse
- PROJECT_FOLDERS =
Common project folder names to truncate from
%w[app lib src test spec features db].freeze
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Class Method Summary collapse
-
.truncate(file_path) ⇒ String
Truncates a file path to show only the relevant project structure starting from the first project folder found.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ PathTruncator
constructor
A new instance of PathTruncator.
-
#truncate ⇒ Object
:reek:TooManyStatements.
Constructor Details
#initialize(file_path) ⇒ PathTruncator
25 26 27 |
# File 'lib/skunk/generators/html/path_truncator.rb', line 25 def initialize(file_path) @file_path = file_path.to_s end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/skunk/generators/html/path_truncator.rb', line 8 def file_path @file_path end |
Class Method Details
.truncate(file_path) ⇒ String
Truncates a file path to show only the relevant project structure starting from the first project folder found
:reek:NilCheck
19 20 21 22 23 |
# File 'lib/skunk/generators/html/path_truncator.rb', line 19 def self.truncate(file_path) return file_path if file_path.nil? new(file_path).truncate end |
Instance Method Details
#truncate ⇒ Object
:reek:TooManyStatements
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/skunk/generators/html/path_truncator.rb', line 30 def truncate return file_path if file_path.empty? path_parts = file_path.split("/") folder_index = path_parts.find_index do |part| PROJECT_FOLDERS.include?(part) end if folder_index # rubocop:disable Style/SlicingWithRange path_parts[folder_index..-1].join("/") # rubocop:enable Style/SlicingWithRange else file_path end end |