1 | /**
|
2 | * Copyright 2014 Skytap Inc.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | **/
|
16 |
|
17 | var _ = require('underscore');
|
18 |
|
19 | /**
|
20 | * Module to help with common path manipulation.
|
21 | **/
|
22 | var Path = function(path) {
|
23 | this._path = path;
|
24 | };
|
25 |
|
26 | _.extend(Path.prototype, {
|
27 |
|
28 | //////////////////////////////////////////////////////////////////////////
|
29 | // Public methods ///////////////////////////////////////////////////////
|
30 | ////////////////////////////////////////////////////////////////////////
|
31 |
|
32 | /**
|
33 | * Path.isCoffeescriptFile() -> Boolean
|
34 | **/
|
35 | isCoffeescriptFile : function () {
|
36 | return this._hasExtension('.coffee');
|
37 | },
|
38 |
|
39 | /**
|
40 | * Path.isJavascriptFile() -> Boolean
|
41 | **/
|
42 | isJavascriptFile : function() {
|
43 | return this._hasExtension('.js');
|
44 | },
|
45 |
|
46 | //////////////////////////////////////////////////////////////////////////
|
47 | // Psuedo-private methods ///////////////////////////////////////////////
|
48 | ////////////////////////////////////////////////////////////////////////
|
49 |
|
50 | /**
|
51 | * Path._hasExtension(path, extension) -> Boolean
|
52 | * - path (String)
|
53 | * - extension (String)
|
54 | **/
|
55 | _hasExtension : function(extension) {
|
56 | var index = this._path.indexOf(extension);
|
57 | return index > 0 && index === this._path.length - extension.length;
|
58 | }
|
59 | });
|
60 |
|
61 | module.exports = Path; |
\ | No newline at end of file |