Class: WWWJDic::Parsers::Dict
- Inherits:
-
Object
- Object
- WWWJDic::Parsers::Dict
- Includes:
- Utils::Raisers
- Defined in:
- lib/wwwjdic/parsers/dict.rb
Overview
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
- Copyright
-
© 2014-2021 Marco Bresciani
- License
-
GNU General Public License version 3
Instance Method Summary collapse
-
#parse(value = '1') ⇒ Object
The parsable duck type interface to every parser usage.
Methods included from Utils::Raisers
#raiser_array, #raiser_downcase, #raiser_to_i
Instance Method Details
#parse(value = '1') ⇒ Object
The parsable duck type interface to every parser usage.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |