Class: FlEd::FileListingBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fled/file_listing_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listing = FileListing.new) ⇒ FileListingBuilder

Returns a new instance of FileListingBuilder.



4
5
6
7
# File 'lib/fled/file_listing_builder.rb', line 4

def initialize listing = FileListing.new
  @listing = listing
  @folders = []
end

Instance Attribute Details

#listingObject

Returns the value of attribute listing.



3
4
5
# File 'lib/fled/file_listing_builder.rb', line 3

def listing
  @listing
end

Instance Method Details

#add(name, full_path) ⇒ Object



31
32
33
# File 'lib/fled/file_listing_builder.rb', line 31

def add name, full_path
  add_object full_path, false
end

#add_object(path, dir) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fled/file_listing_builder.rb', line 8

def add_object path, dir
  uid = next_uid
  name = File.basename(path)
  object = @listing.add(uid,
    :path => path,
    :name => File.basename(path),
    :parent => @object_stack.last,
    :line => "#{"  " * depth}#{name}#{dir ? "/" : ""}"
  )
  object[:dir] = true if dir
  object
end

#depthObject



20
# File 'lib/fled/file_listing_builder.rb', line 20

def depth ; @folders.count ; end

#enter(dir) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/fled/file_listing_builder.rb', line 22

def enter dir
  if depth.zero?
    @object_stack = []
  else
    @object_stack.push add_object(dir, true)
  end
  @folders << dir
  true
end

#full_path(*args) ⇒ Object



21
# File 'lib/fled/file_listing_builder.rb', line 21

def full_path *args ; File.join((@folders || []) + args) ; end

#leaveObject



34
35
36
37
# File 'lib/fled/file_listing_builder.rb', line 34

def leave
  @object_stack.pop
  @folders.pop
end