Class: SVNx::Entries
- Inherits:
-
Object
- Object
- SVNx::Entries
- Includes:
- Enumerable, Logue::Loggable
- Defined in:
- lib/svnx/base/entries.rb
Overview
this is a parse/process on-demand list of entries, acting like an Enumerable.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#[](idx) ⇒ Object
this doesn’t handle negative indices.
- #create_entry(xmlelement) ⇒ Object
- #each(&blk) ⇒ Object
- #get_elements(doc) ⇒ Object
-
#initialize(args = Hash.new) ⇒ Entries
constructor
A new instance of Entries.
Constructor Details
#initialize(args = Hash.new) ⇒ Entries
Returns a new instance of Entries.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/svnx/base/entries.rb', line 16 def initialize args = Hash.new # it's a hash, but indexed with integers, for non-sequential access: @entries = Hash.new if xmllines = args[:xmllines] if xmllines.kind_of? Array xmllines = xmllines.join '' end doc = REXML::Document.new xmllines @elements = get_elements doc @size = @elements.size elsif args[:xmlentries] raise "argument xmlentries is no longer supported" end end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
14 15 16 |
# File 'lib/svnx/base/entries.rb', line 14 def size @size end |
Instance Method Details
#[](idx) ⇒ Object
this doesn’t handle negative indices
43 44 45 46 47 48 49 50 51 |
# File 'lib/svnx/base/entries.rb', line 43 def [] idx if entry = @entries[idx] return entry end if idx < 0 && idx >= size raise "error: index #{idx} is not in range(0 .. #{size})" end @entries[idx] = create_entry(@elements[idx + 1]) end |
#create_entry(xmlelement) ⇒ Object
38 39 40 |
# File 'lib/svnx/base/entries.rb', line 38 def create_entry xmlelement raise "create_entry must be implemented for: #{self.class}" end |
#each(&blk) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/svnx/base/entries.rb', line 53 def each(&blk) # all elements must be processed before each can run: if @elements # a little confusing here: REXML does each_with_index with idx # zero-based, but elements[0] is invalid. @elements.each_with_index do |element, idx| @entries[idx] ||= create_entry(element) end @elements = nil end @entries.keys.sort.collect { |idx| @entries[idx] }.each(&blk) end |
#get_elements(doc) ⇒ Object
34 35 36 |
# File 'lib/svnx/base/entries.rb', line 34 def get_elements doc raise "get_elements must be implemented for: #{self.class}" end |