Class: Munge::System::ItemFactory::ItemIdentifier
- Inherits:
-
Object
- Object
- Munge::System::ItemFactory::ItemIdentifier
- Defined in:
- lib/munge/system/item_factory/item_identifier.rb
Instance Method Summary collapse
- #call(relpath) ⇒ Object
-
#initialize(remove_extensions:) ⇒ ItemIdentifier
constructor
A new instance of ItemIdentifier.
Constructor Details
#initialize(remove_extensions:) ⇒ ItemIdentifier
Returns a new instance of ItemIdentifier.
5 6 7 |
# File 'lib/munge/system/item_factory/item_identifier.rb', line 5 def initialize(remove_extensions:) @remove_extension_regex = join_regex_strings(remove_extensions) end |
Instance Method Details
#call(relpath) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/munge/system/item_factory/item_identifier.rb', line 9 def call(relpath) dirname = Munge::Util::Path.dirname(relpath) basename = Munge::Util::Path.basename_no_extension(relpath) extensions = Munge::Util::Path.extnames(relpath) filtered_extensions = extensions .map { |ext| @remove_extension_regex.match(ext) || ext } .select { |ext| ext.is_a?(String) } new_basename = [basename, *filtered_extensions].join(".") Munge::Util::Path.join(dirname, new_basename) end |