class Lab42::NHash::Enum

Attributes

parent[R]

Public Class Methods

new(enum, options) click to toggle source
# File lib/lab42/nhash/enum.rb, line 45
def initialize enum, options
  @enum    = enum
  @parent  = options[:parent]
  @options = options
end

Public Instance Methods

[](idx) click to toggle source
# File lib/lab42/nhash/enum.rb, line 20
def [] idx
  Lab42::NHash.from_value @enum[idx], @options
end
each(blk=nil, &block) click to toggle source
# File lib/lab42/nhash/enum.rb, line 24
def each blk=nil, &block
  behavior = blk || block
  @enum.each do | ele |
    behavior.( Lab42::NHash.from_value ele, @options )
  end
end
fetch!(idx) click to toggle source
# File lib/lab42/nhash/enum.rb, line 31
def fetch! idx
  result = self[ idx ]
  return result unless String === result

  ERB.new( result ).result @parent.current_binding
end
get(keyexp=nil, &block) click to toggle source
# File lib/lab42/nhash/enum.rb, line 38
def get keyexp=nil, &block
  behavior = block || keyexp
  raise ArgumentError, 'need key or behavior' unless behavior
  Proc === behavior ? _get_with_behavior( behavior ) : _get_with_key( keyexp )
end

Private Instance Methods

_get_with_behavior(behavior) click to toggle source
# File lib/lab42/nhash/enum.rb, line 61
def _get_with_behavior behavior
  each do |ele, sentinel|
    begin
      return _invoke behavior, ele
    rescue KeyError
    end
  end
  raise KeyError, "key not found: #{keyexp.inspect}"
  
end
_get_with_key(keyexp) click to toggle source
# File lib/lab42/nhash/enum.rb, line 51
def _get_with_key keyexp
  each do |ele, sentinel|
    begin
      return ele.get keyexp
    rescue KeyError
    end
  end
  raise KeyError, "key not found: #{keyexp.inspect}"
end