Class: Polygon::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/polygon/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, relative_path, options = {}) ⇒ Entry

Returns a new instance of Entry.



6
7
8
9
10
# File 'lib/polygon/entry.rb', line 6

def initialize(root, relative_path, options = {})
  @root          = Path(root)
  @relative_path = Path(relative_path)
  @options       = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/polygon/entry.rb', line 4

def options
  @options
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



4
5
6
# File 'lib/polygon/entry.rb', line 4

def relative_path
  @relative_path
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/polygon/entry.rb', line 4

def root
  @root
end

Instance Method Details

#/(path) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/polygon/entry.rb', line 24

def /(path)
  entry = Entry.new(root, self.relative_path / path, options)
  if entry.path.inside?(root)
    entry
  else
    nil
  end
end

#==(other) ⇒ Object



56
57
58
# File 'lib/polygon/entry.rb', line 56

def ==(other)
  other.is_a?(Entry) and other.path == path
end

#ancestors_or_self(filter_unexisting = false) ⇒ Object



45
46
47
48
# File 'lib/polygon/entry.rb', line 45

def ancestors_or_self(filter_unexisting = false)
  res = _ancestors_or_self
  filter_unexisting ? res.select{|f| f.path.exist?} : res
end

#exist?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/polygon/entry.rb', line 16

def exist?
  path.exist?
end

#hashObject



60
61
62
# File 'lib/polygon/entry.rb', line 60

def hash
  path.hash
end

#index?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/polygon/entry.rb', line 20

def index?
  path.basename.rm_ext.to_s == "index"
end

#parentObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/polygon/entry.rb', line 33

def parent
  @parent ||= begin
    return nil unless base = self/".."
    idx = -1
    if index?
      idx = index_files.index(path.basename.to_s) - 1
      base = base/".." if idx == -1
    end
    base ? base/index_files[idx] : nil
  end
end

#pathObject



12
13
14
# File 'lib/polygon/entry.rb', line 12

def path
  root / relative_path
end

#to_hashObject



50
51
52
53
54
# File 'lib/polygon/entry.rb', line 50

def to_hash
  ancestors_or_self(true).inject({}) do |h,entry|
    merge(h, entry.data)
  end
end