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
46 def parse(value = '1')
47   raise ArgumentError, I18n.t('error.nil') if value.nil?
48   raise ArgumentError, I18n.t('error.param', value: value) unless value.respond_to? :length
49   raise ArgumentError, I18n.t('error.param', value: value) if value.empty?
50
51   if value.length == 1
52     raiser_array('error.param', value, DICTIONARY_CODES)
53     value
54   elsif value.length > 1
55     raiser_array('error.param', value, DICTIONARY_NAMES)
56     DICTS_BY_NAMES[value]
57   end
58 end