Class: Mapscript::MapscriptEnumerable
- Inherits:
-
Object
- Object
- Mapscript::MapscriptEnumerable
- Includes:
- Enumerable
- Defined in:
- lib/mapscript/mapscript_extensions.rb
Overview
Generic iterator for Mapscript collections
Direct Known Subclasses
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #each ⇒ Object
-
#initialize(parent, size_method, getter) ⇒ MapscriptEnumerable
constructor
A new instance of MapscriptEnumerable.
- #size ⇒ Object
Constructor Details
#initialize(parent, size_method, getter) ⇒ MapscriptEnumerable
Returns a new instance of MapscriptEnumerable.
11 12 13 |
# File 'lib/mapscript/mapscript_extensions.rb', line 11 def initialize(parent, size_method, getter) @parent, @size_method, @getter = parent, size_method, getter end |
Instance Method Details
#[](idx) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mapscript/mapscript_extensions.rb', line 25 def [](idx) case idx when Fixnum if idx >= 0 @parent.send(@getter, idx) else @parent.send(@getter, size+idx) end when Range to_a[idx] else raise TypeError, "Unsupported type for index" end end |
#each ⇒ Object
19 20 21 22 23 |
# File 'lib/mapscript/mapscript_extensions.rb', line 19 def each 0.upto(size-1) do |idx| yield @parent.send(@getter, idx) end end |
#size ⇒ Object
15 16 17 |
# File 'lib/mapscript/mapscript_extensions.rb', line 15 def size @parent.send(@size_method) end |