class DwCAContentAnalyzer::Column
Attributes
index[R]
length[R]
type[R]
Public Class Methods
new(index, contents, *detectors)
click to toggle source
# File lib/dwca_content_analyzer/column.rb, line 9 def initialize(index, contents, *detectors) raise ArgumentError unless index.is_a? Integer detectors = [] if detectors.include? :none detectors = %i[type= length=] if detectors.include? :all detectors.map! { |d| (d.id2name + '=').to_sym } @index = index @type = nil @length = nil analyze(contents, detectors) end
Private Instance Methods
analyze(contents, detectors)
click to toggle source
# File lib/dwca_content_analyzer/column.rb, line 22 def analyze(contents, detectors) return if detectors.empty? cells = contents.compact detectors.each { |detector| send(detector, cells) } end
collapse(types)
click to toggle source
collapses all types encountered in a file's column into a single type
# File lib/dwca_content_analyzer/column.rb, line 29 def collapse(types) return types.first if types.size == 1 return nil if types.empty? return String if string?(types) return Float if float?(types) String end
float?(types)
click to toggle source
# File lib/dwca_content_analyzer/column.rb, line 45 def float?(types) types.size == 2 && types.include?(Float) && types.include?(Integer) end
length=(cells)
click to toggle source
# File lib/dwca_content_analyzer/column.rb, line 37 def length=(cells) @length = cells.map(&:to_s).map(&:length).max || 0 end
string?(types)
click to toggle source
# File lib/dwca_content_analyzer/column.rb, line 49 def string?(types) types.include?(String) end
type=(cells)
click to toggle source
# File lib/dwca_content_analyzer/column.rb, line 41 def type=(cells) @type = collapse(cells.map(&:class).uniq) end