Skip to content

Instantly share code, notes, and snippets.

@spohlenz
Created October 4, 2012 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spohlenz/3831540 to your computer and use it in GitHub Desktop.
Save spohlenz/3831540 to your computer and use it in GitHub Desktop.
def extract_extensions(filename)
extensions, *name = filename.split(".").reverse.slice_before { |f| f[" "] }.to_a
[name.flatten.reverse.join("."), extensions.reverse]
end
describe "#extract_extensions" do
specify { extract_extensions("some file name.with dots.html.markdown").should == ["some file name.with dots", ["html", "markdown"]]}
specify { extract_extensions("some file name with.dots.html.markdown").should == ["some file name with", ["dots", "html", "markdown"]]}
specify { extract_extensions("a b.c d.e").should == ["a b.c d", ["e"]] }
specify { extract_extensions("a.b c.a").should == ["a.b c", ["a"]] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment