Class: Polygon::Entry
- Inherits:
-
Object
- Object
- Polygon::Entry
- Defined in:
- lib/polygon/entry.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #/(path) ⇒ Object
- #==(other) ⇒ Object
- #ancestors_or_self(filter_unexisting = false) ⇒ Object
- #exist? ⇒ Boolean
- #hash ⇒ Object
- #index? ⇒ Boolean
-
#initialize(root, relative_path, options = {}) ⇒ Entry
constructor
A new instance of Entry.
- #parent ⇒ Object
- #path ⇒ Object
- #to_hash ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/polygon/entry.rb', line 4 def @options end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
4 5 6 |
# File 'lib/polygon/entry.rb', line 4 def relative_path @relative_path end |
#root ⇒ Object (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, ) 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
16 17 18 |
# File 'lib/polygon/entry.rb', line 16 def exist? path.exist? end |
#hash ⇒ Object
60 61 62 |
# File 'lib/polygon/entry.rb', line 60 def hash path.hash end |
#index? ⇒ Boolean
20 21 22 |
# File 'lib/polygon/entry.rb', line 20 def index? path.basename.rm_ext.to_s == "index" end |
#parent ⇒ Object
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 |
#path ⇒ Object
12 13 14 |
# File 'lib/polygon/entry.rb', line 12 def path root / relative_path end |
#to_hash ⇒ Object
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 |