Sha256: 7cab599aa7530fb84f8dfc8aabf7a6ae041da8c0141efd2512f83a39d5715fcf

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

class NameSpotter
  class ScientificName
    attr_reader :verbatim, :scientific, :start_pos, :end_pos, :score

    def self.normalize(name)
      name = name.gsub(",", " ") 
      name = name.gsub(/\s+/, " ")
    end

    def initialize(verbatim_name, options={})
      @verbatim = verbatim_name
      if options[:start_position]
        @start_pos = options[:start_position]
        @end_pos = @start_pos + @verbatim.length - 1
      end
      @score = options[:score] if options[:score]
      @scientific = options[:scientific_name] if options[:scientific_name]
    end

    # Use this in specs
    def eql?(other_name)
      other_name.is_a?(Name) &&
        other_name.verbatim.eql?(verbatim) &&
        other_name.scientific.eql?(scientific) &&
        other_name.start_pos.eql?(start_pos) && 
        other_name.end_pos.eql?(end_pos) && 
        other_name.score.eql?(score)
    end

    def to_hash
      name_hash = {:verbatim => verbatim}
      name_hash[:scientificName] = scientific if scientific
      name_hash[:offsetStart] = start_pos if start_pos
      name_hash[:offsetEnd] = end_pos if end_pos
      name_hash
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
name-spotter-0.2.4 lib/name-spotter/scientific_name.rb
name-spotter-0.2.3 lib/name-spotter/scientific_name.rb
name-spotter-0.2.2 lib/name-spotter/scientific_name.rb
name-spotter-0.2.1 lib/name-spotter/scientific_name.rb
name-spotter-0.2.0 lib/name-spotter/scientific_name.rb