Class: Realize::File::Basename

Inherits:
Object
  • Object
show all
Defined in:
lib/realize/file/basename.rb

Overview

Takes the value and strips out the directory. Suffix is provided as an option which strips out the extension (last period and beyond). If ‘.*’ is passed in as the suffix then any extension will be stripped. Note that files with multiple extensions will only have their last extesion removed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suffix: '') ⇒ Basename

Returns a new instance of Basename.



21
22
23
24
25
# File 'lib/realize/file/basename.rb', line 21

def initialize(suffix: '')
  @suffix = suffix.to_s

  freeze
end

Instance Attribute Details

#suffixObject (readonly)

Returns the value of attribute suffix.



19
20
21
# File 'lib/realize/file/basename.rb', line 19

def suffix
  @suffix
end

Instance Method Details

#transform(_resolver, value, _time, _record) ⇒ Object



27
28
29
# File 'lib/realize/file/basename.rb', line 27

def transform(_resolver, value, _time, _record)
  ::File.basename(value.to_s, suffix)
end