Class: StructuredReader::JSONReader::SelectionContext

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

Instance Method Summary collapse

Constructor Details

#initialize(target, where = "", found = []) ⇒ SelectionContext

Returns a new instance of SelectionContext.



379
380
381
382
383
# File 'lib/structured_reader.rb', line 379

def initialize(target, where = "", found = [])
  @target = target
  @where = where
  @found = found
end

Instance Method Details

#accept(fragment) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/structured_reader.rb', line 385

def accept(fragment)
  if File.fnmatch(@target, @where)
    @found << fragment
    fragment
  else
    if @found.any?
      @found.first
    else
      unless @where.empty?
        fragment
      end
    end
  end
end

#flunk(fragment, reason) ⇒ Object



400
401
402
# File 'lib/structured_reader.rb', line 400

def flunk(fragment, reason)
  nil
end

#push(path) ⇒ Object



404
405
406
407
408
# File 'lib/structured_reader.rb', line 404

def push(path)
  if @found.empty?
    yield self.class.new(@target, @where + path, @found)
  end
end