Class: Docs::EntryIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/docs/core/entry_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntryIndex


7
8
9
10
# File 'lib/docs/core/entry_index.rb', line 7

def initialize
  @entries = []
  @types = Hash.new { |hash, key| hash[key] = Type.new key }
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries


5
6
7
# File 'lib/docs/core/entry_index.rb', line 5

def entries
  @entries
end

#typesObject (readonly)

Returns the value of attribute types


5
6
7
# File 'lib/docs/core/entry_index.rb', line 5

def types
  @types
end

Instance Method Details

#add(entry) ⇒ Object


12
13
14
15
16
17
18
# File 'lib/docs/core/entry_index.rb', line 12

def add(entry)
  if entry.is_a? Array
    entry.each(&method(:add))
  else
    add_entry(entry) unless entry.root?
  end
end

#as_jsonObject


30
31
32
# File 'lib/docs/core/entry_index.rb', line 30

def as_json
  { entries: entries_as_json, types: types_as_json }
end

#empty?Boolean Also known as: blank?


20
21
22
# File 'lib/docs/core/entry_index.rb', line 20

def empty?
  @entries.empty?
end

#lengthObject


26
27
28
# File 'lib/docs/core/entry_index.rb', line 26

def length
  @entries.length
end

#to_jsonObject


34
35
36
# File 'lib/docs/core/entry_index.rb', line 34

def to_json
  JSON.generate(as_json)
end