Class: Fable::Path::Component
- Inherits:
-
Object
- Object
- Fable::Path::Component
- Defined in:
- lib/fable/path.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_component) ⇒ Object
-
#initialize(options) ⇒ Component
constructor
A new instance of Component.
- #is_index? ⇒ Boolean
- #is_parent? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(options) ⇒ Component
Returns a new instance of Component.
149 150 151 152 153 154 155 156 157 |
# File 'lib/fable/path.rb', line 149 def initialize() if [:index] self.index = [:index] self.name = nil elsif [:name] self.name = [:name] self.index = -1 end end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
131 132 133 |
# File 'lib/fable/path.rb', line 131 def index @index end |
#name ⇒ Object
Returns the value of attribute name.
131 132 133 |
# File 'lib/fable/path.rb', line 131 def name @name end |
Class Method Details
.component_type(value) ⇒ Object
141 142 143 144 145 146 147 |
# 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 |
Instance Method Details
#==(other_component) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# 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? ⇒ Boolean
133 134 135 |
# File 'lib/fable/path.rb', line 133 def is_index? index >= 0 end |
#is_parent? ⇒ Boolean
137 138 139 |
# File 'lib/fable/path.rb', line 137 def is_parent? name == Path::PARENT_ID end |
#to_s ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/fable/path.rb', line 159 def to_s if is_index? index.to_s else name end end |