Class: Restruct::Id

Inherits:
String
  • Object
show all
Defined in:
lib/restruct/id.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, separator = nil) ⇒ Id



6
7
8
9
# File 'lib/restruct/id.rb', line 6

def initialize(id, separator=nil)
  @separator = separator || Restruct.id_separator
  super id.to_s
end

Instance Attribute Details

#separatorObject (readonly)

Returns the value of attribute separator.



4
5
6
# File 'lib/restruct/id.rb', line 4

def separator
  @separator
end

Instance Method Details

#[](id) ⇒ Object



11
12
13
# File 'lib/restruct/id.rb', line 11

def [](id)
  Id.new "#{to_s}#{separator}#{id}", separator
end

#sectionsObject



15
16
17
# File 'lib/restruct/id.rb', line 15

def sections
  split(separator).map { |s| Id.new s, separator }
end