Class: Flame::Path::Part
- Inherits:
-
Object
- Object
- Flame::Path::Part
- Extended by:
- Forwardable
- Defined in:
- lib/flame/path.rb
Overview
Class for one part of Path
Constant Summary collapse
- ARG_CHAR =
':'- ARG_CHAR_OPT =
'?'
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Compare with another.
-
#arg? ⇒ true, false
Is the path part an argument.
-
#freeze ⇒ Object
Freeze object.
-
#initialize(part, arg: false) ⇒ Part
constructor
Create new instance from String.
-
#opt_arg? ⇒ true, false
Is the path part an optional argument.
-
#to_s ⇒ String
(also: #to_str)
Convert path part to String.
-
#to_sym ⇒ Symbol
Path part as a Symbol without arguments characters.
Constructor Details
#initialize(part, arg: false) ⇒ Part
Create new instance from String
208 209 210 211 |
# File 'lib/flame/path.rb', line 208 def initialize(part, arg: false) @part = "#{ARG_CHAR if arg}#{ARG_CHAR_OPT if arg == :opt}#{part}" freeze end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Compare with another
222 223 224 |
# File 'lib/flame/path.rb', line 222 def ==(other) to_s == other.to_s end |
#arg? ⇒ true, false
Is the path part an argument
237 238 239 |
# File 'lib/flame/path.rb', line 237 def arg? @part.start_with? ARG_CHAR end |
#freeze ⇒ Object
Freeze object
214 215 216 217 |
# File 'lib/flame/path.rb', line 214 def freeze @part.freeze super end |
#opt_arg? ⇒ true, false
Is the path part an optional argument
243 244 245 |
# File 'lib/flame/path.rb', line 243 def opt_arg? arg? && @part[1] == ARG_CHAR_OPT end |
#to_s ⇒ String Also known as: to_str
Convert path part to String
230 231 232 |
# File 'lib/flame/path.rb', line 230 def to_s @part end |
#to_sym ⇒ Symbol
Path part as a Symbol without arguments characters
253 254 255 |
# File 'lib/flame/path.rb', line 253 def to_sym @part.delete(ARG_CHAR + ARG_CHAR_OPT).to_sym end |