class Fable::Path::Component

Attributes

index[RW]
name[RW]

Public Class Methods

component_type(value) click to toggle source
# File lib/fable/path.rb, line 141
def self.component_type(value)
  if value.is_a?(Numeric) || value.match?(/^\d+$/)
    return {index: Integer(value)}
  else
    return {name: value}
  end
end
new(options) click to toggle source
# File lib/fable/path.rb, line 149
def initialize(options)
  if options[:index]
    self.index = options[:index]
    self.name = nil
  elsif options[:name]
    self.name = options[:name]
    self.index = -1
  end
end
parent_component() click to toggle source
# File lib/fable/path.rb, line 181
def self.parent_component
  self.new(name: Path::PARENT_ID)
end

Public Instance Methods

==(other_component) click to toggle source
# File lib/fable/path.rb, line 167
def ==(other_component)
  return false if other_component.nil?

  if self.is_index? == other_component.is_index?
    if is_index?
      return self.index == other_component.index
    else
      return self.name == other_component.name
    end
  end

  return false
end
is_index?() click to toggle source
# File lib/fable/path.rb, line 133
def is_index?
  index >= 0
end
is_parent?() click to toggle source
# File lib/fable/path.rb, line 137
def is_parent?
  name == Path::PARENT_ID
end
to_s() click to toggle source
# File lib/fable/path.rb, line 159
def to_s
  if is_index?
    index.to_s
  else
    name
  end
end