Class: Bio::FlatFile::AutoDetect::RuleProc

Inherits:
RuleTemplate show all
Defined in:
lib/bio/io/flatfile/autodetection.rb

Overview

A autodetection rule that passes data to the proc object.

Instance Attribute Summary

Attributes inherited from RuleTemplate

#higher_priority_elements, #lower_priority_elements, #name

Instance Method Summary collapse

Methods inherited from RuleTemplate

[], #is_prior_to

Constructor Details

#initialize(*dbclasses, &proc) ⇒ RuleProc

Creates a new instance.



199
200
201
202
203
204
205
# File 'lib/bio/io/flatfile/autodetection.rb', line 199

def initialize(*dbclasses, &proc)
  super()
  @proc = proc
  @dbclasses = nil
  @dbclasses_lazy = dbclasses
  @name = dbclasses.collect { |x| x.to_s }.join('|')
end

Instance Method Details

#dbclassesObject

database classes (lazy evaluation)



208
209
210
211
212
213
# File 'lib/bio/io/flatfile/autodetection.rb', line 208

def dbclasses
  unless @dbclasses
    @dbclasses = @dbclasses_lazy.collect { |x| get_dbclass(x) }
  end
  @dbclasses
end

#guess(text, meta) ⇒ Object

If given text (and/or meta information) is known, returns the database class. Otherwise, returns nil or false.

Refer RuleTemplate#guess for meta.



220
221
222
# File 'lib/bio/io/flatfile/autodetection.rb', line 220

def guess(text, meta)
  @proc.call(text)
end