Class: Semi::Variables::Path
Constant Summary collapse
- @@path_re =
Regexp.new('^(?<path>(?:\/|\.{1,2}\/|~(?:[a-z_][a-z0-9_]{0,30})?\/?|[^~][^\/\000]+\/)*?)(?<file>[^\/\000]+)?$')
Class Method Summary collapse
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize(val) ⇒ Path
constructor
A new instance of Path.
- #path ⇒ Object
- #validate ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(val) ⇒ Path
Returns a new instance of Path.
8 9 10 11 12 13 14 |
# File 'lib/semi/variables/path.rb', line 8 def initialize(val) if @@path_re.match(val) @value = val else raise Semi::VariableError, '#{val} does not look like a path' end end |
Class Method Details
.validate(value) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/semi/variables/path.rb', line 20 def self.validate(value) if ['String', 'Semi::Variables::Path'].include? value.class.to_s if @@path_re.match(value) return true end end false end |
Instance Method Details
#file ⇒ Object
36 37 38 39 40 41 |
# File 'lib/semi/variables/path.rb', line 36 def file match = @@path_re.match(@value) if match match['file'] end end |
#path ⇒ Object
29 30 31 32 33 34 |
# File 'lib/semi/variables/path.rb', line 29 def path match = @@path_re.match(@value) if match match['path'] end end |
#validate ⇒ Object
16 17 18 |
# File 'lib/semi/variables/path.rb', line 16 def validate self.validate(@value) end |