Class: Flame::Path::Part

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(part, arg: false) ⇒ Part

Create new instance from String

Parameters:

  • part (String)

    path part as String

  • arg (Boolean) (defaults to: false)

    is this part an argument



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

Parameters:

Returns:

  • (true, false)

    equal or not



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

Returns:

  • (true, false)

    an argument or not



237
238
239
# File 'lib/flame/path.rb', line 237

def arg?
  @part.start_with? ARG_CHAR
end

#freezeObject

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

Returns:

  • (true, false)

    an optional argument or not



243
244
245
# File 'lib/flame/path.rb', line 243

def opt_arg?
  arg? && @part[1] == ARG_CHAR_OPT
end

#to_sString Also known as: to_str

Convert path part to String

Returns:

  • (String)

    path part as String



230
231
232
# File 'lib/flame/path.rb', line 230

def to_s
  @part
end

#to_symSymbol

Path part as a Symbol without arguments characters

Returns:

  • (Symbol)

    clean Symbol



253
254
255
# File 'lib/flame/path.rb', line 253

def to_sym
  @part.delete(ARG_CHAR + ARG_CHAR_OPT).to_sym
end