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.



356
357
358
359
360
# File 'lib/structured_reader.rb', line 356

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

Instance Method Details

#accept(fragment) ⇒ Object



362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/structured_reader.rb', line 362

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



377
378
379
# File 'lib/structured_reader.rb', line 377

def flunk(fragment, reason)
  nil
end

#push(path) ⇒ Object



381
382
383
384
385
# File 'lib/structured_reader.rb', line 381

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