#-- # wwwjdic # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani # # This file is part of wwwjdic. # # wwwjdic is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # wwwjdic is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with wwwjdic. If not, see . #++ require_relative '../constants' require_relative '../utils/raisers' module WWWJDic module Parsers # 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}[mailto:marcobresciani_1974@libero.it] # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani # License:: GNU General Public License version 3 class Dict include Utils::Raisers # The parsable duck type interface to every parser usage. 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 else if value.length > 1 raiser_array('error.param', value, DICTIONARY_NAMES) DICTS_BY_NAMES[value] end end end end end end