Class: NameSpotter::ScientificName
- Defined in:
- lib/name-spotter/scientific_name.rb
Instance Attribute Summary collapse
-
#end_pos ⇒ Object
readonly
Returns the value of attribute end_pos.
-
#scientific ⇒ Object
readonly
Returns the value of attribute scientific.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#start_pos ⇒ Object
readonly
Returns the value of attribute start_pos.
-
#verbatim ⇒ Object
readonly
Returns the value of attribute verbatim.
Class Method Summary collapse
Instance Method Summary collapse
-
#eql?(other_name) ⇒ Boolean
Use this in specs.
-
#initialize(verbatim_name, options = {}) ⇒ ScientificName
constructor
A new instance of ScientificName.
- #to_hash ⇒ Object
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, ={}) @verbatim = verbatim_name if [:start_position] @start_pos = [:start_position] @end_pos = @start_pos + @verbatim.length - 1 end @score = [:score] if [:score] @scientific = [:scientific_name] if [:scientific_name] end |
Instance Attribute Details
#end_pos ⇒ Object (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 |
#scientific ⇒ Object (readonly)
Returns the value of attribute scientific.
3 4 5 |
# File 'lib/name-spotter/scientific_name.rb', line 3 def scientific @scientific end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
3 4 5 |
# File 'lib/name-spotter/scientific_name.rb', line 3 def score @score end |
#start_pos ⇒ Object (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 |
#verbatim ⇒ Object (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
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_hash ⇒ Object
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 |