Class: Compath::Guide

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/compath/guide.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, scan: true, desc: nil) ⇒ Guide

Returns a new instance of Guide.



8
9
10
11
12
13
# File 'lib/compath/guide.rb', line 8

def initialize(path, scan: true, desc: nil)
  # claenpath is for dirty configurated guide
  @pathname = Pathname.new(path).cleanpath
  @scan_children = scan
  @description = desc
end

Instance Attribute Details

#pathnameObject (readonly)

Returns the value of attribute pathname.



6
7
8
# File 'lib/compath/guide.rb', line 6

def pathname
  @pathname
end

#scan_childrenObject (readonly)

Returns the value of attribute scan_children.



6
7
8
# File 'lib/compath/guide.rb', line 6

def scan_children
  @scan_children
end

Instance Method Details

#ancestorsObject



21
22
23
24
25
26
27
28
# File 'lib/compath/guide.rb', line 21

def ancestors
  ancestors = []
  pathname.ascend do |path|
    next if path == pathname
    ancestors << self.class.new(path.to_path)
  end
  ancestors
end

#childrenObject



15
16
17
18
19
# File 'lib/compath/guide.rb', line 15

def children
  pathname.children.map do |child|
    self.class.new(child.to_path)
  end
end

#object_keyObject



48
49
50
51
52
53
54
# File 'lib/compath/guide.rb', line 48

def object_key
  if directory?
    pathname.to_s + '/'
  else
    pathname.to_s
  end
end

#to_objectObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/compath/guide.rb', line 30

def to_object
  scan_or_not = if !directory? || @scan_children
                  {}
                else
                  {
                    'scan' => false
                  }
                end

  object = {
             object_key => {
               'desc' => @description
             }.merge(scan_or_not)
           }

  object
end