class WWWJDic::Parsers::Dict

This class is an implementation of the Parsable duck type that checks the dictionary type. The only needed parameter is a valid dictionary.

n = dictionary to use (1 = EDICT, 3 = ENAMDICT, etc. Examine the source of one of the pages to get the full list of codes.)

Author

Marco Bresciani

Copyright

© 2014-2021 Marco Bresciani

License

GNU General Public License version 3

Public Instance Methods

parse(value = '1') click to toggle source

The parsable duck type interface to every parser usage.

# File lib/wwwjdic/parsers/dict.rb, line 46
def parse(value = '1')
  raise ArgumentError, I18n.t('error.nil') if value.nil?
  raise ArgumentError, I18n.t('error.param', value: value) unless value.respond_to? :length
  raise ArgumentError, I18n.t('error.param', value: value) if value.empty?

  if value.length == 1
    raiser_array('error.param', value, DICTIONARY_CODES)
    value
  elsif value.length > 1
    raiser_array('error.param', value, DICTIONARY_NAMES)
    DICTS_BY_NAMES[value]
  end
end