Class: NameSpotter::ScientificName

Inherits:
Object
  • Object
show all
Defined in:
lib/name-spotter/scientific_name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verbatim_name, options = {}) ⇒ ScientificName

Returns a new instance of ScientificName.



10
11
12
13
14
15
16
17
18
# File 'lib/name-spotter/scientific_name.rb', line 10

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

Instance Attribute Details

#end_posObject (readonly)

Returns the value of attribute end_pos.



3
4
5
# File 'lib/name-spotter/scientific_name.rb', line 3

def end_pos
  @end_pos
end

#scientificObject (readonly)

Returns the value of attribute scientific.



3
4
5
# File 'lib/name-spotter/scientific_name.rb', line 3

def scientific
  @scientific
end

#scoreObject (readonly)

Returns the value of attribute score.



3
4
5
# File 'lib/name-spotter/scientific_name.rb', line 3

def score
  @score
end

#start_posObject (readonly)

Returns the value of attribute start_pos.



3
4
5
# File 'lib/name-spotter/scientific_name.rb', line 3

def start_pos
  @start_pos
end

#verbatimObject (readonly)

Returns the value of attribute verbatim.



3
4
5
# File 'lib/name-spotter/scientific_name.rb', line 3

def verbatim
  @verbatim
end

Class Method Details

.normalize(name) ⇒ Object



5
6
7
8
# File 'lib/name-spotter/scientific_name.rb', line 5

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

Instance Method Details

#eql?(other_name) ⇒ Boolean

Use this in specs

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/name-spotter/scientific_name.rb', line 21

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

#to_hashObject



30
31
32
33
34
35
36
# File 'lib/name-spotter/scientific_name.rb', line 30

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