Class: KBuilder::FileSegments
- Inherits:
-
Object
- Object
- KBuilder::FileSegments
- Defined in:
- lib/k_builder/file_segments.rb
Overview
Splits a file into its base parts (file, path, file_name, extension and file_name_only)
Provides the interpolate helper to rebuild a different filename using those segments
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_name_only ⇒ Object
readonly
Returns the value of attribute file_name_only.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(file) ⇒ FileSegments
constructor
A new instance of FileSegments.
- #interpolate(target_file) ⇒ Object
Constructor Details
#initialize(file) ⇒ FileSegments
Returns a new instance of FileSegments.
14 15 16 17 18 19 20 |
# File 'lib/k_builder/file_segments.rb', line 14 def initialize(file) @file = file @path = File.dirname(file) @file_name = File.basename(file) @ext = File.extname(file) @file_name_only = File.basename(file, @ext) end |
Instance Attribute Details
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
11 12 13 |
# File 'lib/k_builder/file_segments.rb', line 11 def ext @ext end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/k_builder/file_segments.rb', line 8 def file @file end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/k_builder/file_segments.rb', line 10 def file_name @file_name end |
#file_name_only ⇒ Object (readonly)
Returns the value of attribute file_name_only.
12 13 14 |
# File 'lib/k_builder/file_segments.rb', line 12 def file_name_only @file_name_only end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/k_builder/file_segments.rb', line 9 def path @path end |
Instance Method Details
#interpolate(target_file) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/k_builder/file_segments.rb', line 22 def interpolate(target_file) # p str.gsub( /#{var}/, 'foo' ) # => "a test foo" target_file .gsub(/\$T_FILE\$/i, file) .gsub(/\$T_PATH\$/i, path) .gsub(/\$T_FILE_NAME\$/i, file_name) .gsub(/\$T_EXT\$/i, ext) .gsub(/\$T_FILE_NAME_ONLY\$/i, file_name_only) end |