Class: Parser

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

Constant Summary collapse

META_REGEX =
/^([a-zA-Z]{1,4}+\.[ ]{1,2})+/

Instance Method Summary collapse

Constructor Details

#initialize(rae_data, word) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
11
# File 'lib/nebrija/parser.rb', line 7

def initialize(rae_data, word)
  @doc = Nokogiri::HTML(rae_data
                    .gsub(/\n+/, '')
                    .gsub(/\s{2,}+/, ' '))
end

Instance Method Details

#parseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nebrija/parser.rb', line 13

def parse
  if valid?
    {
      :status => 'success',
      :type => single? ? 'single' : 'multiple',
      :response => single? ? parse_single : parse_multiple
    }
  else
    {
      :status => 'error',
      :message => 'Word/id does not exist. Sorry.'
    }
  end
end