Class: ScientificNameParser

Inherits:
Object
  • Object
show all
Defined in:
lib/biodiversity/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScientificNameParser

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
  @parsed = nil
end

Class Method Details

.allObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/biodiversity/parser.rb', line 26

def @parsed.all
  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}
  res
end

.all_jsonObject



50
51
52
# File 'lib/biodiversity/parser.rb', line 50

def @parsed.all_json
  self.all.to_json rescue ''
end

.pos_jsonObject



46
47
48
# File 'lib/biodiversity/parser.rb', line 46

def @parsed.pos_json
  self.pos.to_json rescue ''
end

Instance Method Details

#parse(a_string) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/biodiversity/parser.rb', line 23

def parse(a_string)
  @verbatim = a_string
  @parsed = @clean.parse(a_string) || @dirty.parse(a_string) || @canonical.parse(a_string) || {:verbatim => a_string}
  def @parsed.all
    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}
    res
  end
  
  def @parsed.pos_json
    self.pos.to_json rescue ''
  end
  
  def @parsed.all_json
    self.all.to_json rescue ''
  end
  
  @parsed.all
end

#parsedObject



19
20
21
# File 'lib/biodiversity/parser.rb', line 19

def parsed
  @parsed
end