Class: Compath::GuideBook

Inherits:
Object
  • Object
show all
Defined in:
lib/compath/guide_book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guides) ⇒ GuideBook

Returns a new instance of GuideBook.



4
5
6
7
8
# File 'lib/compath/guide_book.rb', line 4

def initialize(guides)
  @index = guides.each_with_object({}) do |guide, hash|
    hash[guide.to_path] = guide
  end
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



3
4
5
# File 'lib/compath/guide_book.rb', line 3

def paths
  @paths
end

Instance Method Details

#guidesObject



10
11
12
# File 'lib/compath/guide_book.rb', line 10

def guides
  @index.values
end

#merge(new_guides) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/compath/guide_book.rb', line 14

def merge(new_guides)
  new_guides.each do |guide|
    puts guide.to_path
    if @index.key?(guide.to_path)
      @index[guide.to_path] = guide
    end
  end
end

#publishObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/compath/guide_book.rb', line 23

def publish
  guides.map do |guide|
    scan_children = true
    scan_children = guide.ancestors.all? do |ancestor|
      @index[ancestor.to_path].scan_children
    end
    next unless scan_children
    guide.to_object
  end.compact
end

#publish_yamlObject



34
35
36
# File 'lib/compath/guide_book.rb', line 34

def publish_yaml
  YAML.dump(publish)
end