Class: Compath::Guide
- Inherits:
-
Object
- Object
- Compath::Guide
- Extended by:
- Forwardable
- Defined in:
- lib/compath/guide.rb
Instance Attribute Summary collapse
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
-
#scan_children ⇒ Object
readonly
Returns the value of attribute scan_children.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #children ⇒ Object
-
#initialize(path, scan: true, desc: nil) ⇒ Guide
constructor
A new instance of Guide.
- #object_key ⇒ Object
- #to_object ⇒ Object
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
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
6 7 8 |
# File 'lib/compath/guide.rb', line 6 def pathname @pathname end |
#scan_children ⇒ Object (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
#ancestors ⇒ Object
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 |
#children ⇒ Object
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_key ⇒ Object
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_object ⇒ Object
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 |