Class: ScientificNameParser
- Inherits:
-
Object
- Object
- ScientificNameParser
- Defined in:
- lib/biodiversity/parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ScientificNameParser
constructor
A new instance of ScientificNameParser.
- #parse(a_string) ⇒ Object
Constructor Details
#initialize ⇒ ScientificNameParser
Returns a new instance of ScientificNameParser.
11 12 13 14 15 16 17 |
# File 'lib/biodiversity/parser.rb', line 11 def initialize @verbatim = '' @clean = ScientificNameCleanParser.new @dirty = ScientificNameDirtyParser.new @canonical = ScientificNameCanonicalParser.new @parser = nil end |
Class Method Details
.pos_json ⇒ Object
42 43 44 |
# File 'lib/biodiversity/parser.rb', line 42 def @parser.pos_json JSON.generate self.pos rescue '' end |
.to_json ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/biodiversity/parser.rb', line 22 def @parser.to_json parsed = self.class != Hash res = {:parsed => parsed} if parsed hybrid = self.hybrid rescue false res.merge!({ :verbatim => self.text_value, :normalized => self.value, :canonical => self.canonical, :hybrid => hybrid, :details => self.details, :positions => self.pos }) else res.merge!(self) end res = {:scientificName => res} JSON.generate res end |
Instance Method Details
#parse(a_string) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/biodiversity/parser.rb', line 19 def parse(a_string) @verbatim = a_string @parser = @clean.parse(a_string) || @dirty.parse(a_string) || @canonical.parse(a_string) || {:verbatim => a_string} def @parser.to_json parsed = self.class != Hash res = {:parsed => parsed} if parsed hybrid = self.hybrid rescue false res.merge!({ :verbatim => self.text_value, :normalized => self.value, :canonical => self.canonical, :hybrid => hybrid, :details => self.details, :positions => self.pos }) else res.merge!(self) end res = {:scientificName => res} JSON.generate res end def @parser.pos_json JSON.generate self.pos rescue '' end @parser end |