#-- # wwwjdic # © 2014 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 . # # SPDX-FileCopyrightText: 2014 Marco Bresciani # # SPDX-License-Identifier: GPL-3.0-or-later #++ require_relative '../constants' module WWWJDic module Parsers # This class is an implementation of the Parsable duck type that # checks the display type. The only needed parameter is the word to # translate. # # k is the key type: # * for dictionary lookups # * for English keys use E, or P to get just "common words", Q to # get an "exact match" and R to get both; # * for Japanese keys use J (this is mandatory for romaji keys), # P to get just "common words" (doesn't work with romaji), K for # keys starting with kanji (first position), and L for kanji keys in # any position. # * for kanji lookups, use M followed by the KANJIDIC letter codes # (B, U, V, N, etc.) or J if a reading or kanji is being provided. # An optional stroke-count or stroke-count range can be included by # placing it between "=" characters; # * for text glossing use G, or H to turn on the "no repeated # translations" option. # * for multi-radical kanji lookups use J for jouyou kanji-only, H # to include JIS X 0212 kanji, and X for anything else. An optional # stroke-count or stroke-count range can be included by placing it # between "=" characters. # * for example sentence lookups with indexed words use E for EUC, # ISO-2022-JP or UCS, S for Shift_JIS and U for UTF-8, followed by # "lookupword=n=kana=". The kana is optional and is there to # disambiguate between different headwords. For "n", 1 => random # selection of 10, anything else => display up to 100 sentences # starting at n. # * for example sentence lookups using a regular expression, use E # for EUC, ISO-2022-JP or UCS, S for Shift_JIS and U for UTF-8, # followed by the search string. Up to 99 example sentences may be # displayed. # # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it] # Copyright:: (C) 2014 Marco Bresciani # License:: GNU General Public License version 3 class Key include Utils::Raisers # The parsable duck type interface to every parser usage. def parse(value = :english) raise ArgumentError, I18n.t('error.nil') if value.nil? raise ArgumentError, I18n.t('error.param', value: value) unless value.is_a? Symbol raiser_array('error.param', value, KEYS.keys) value end end end end