Class: WWWJDic::Parsers::Key

Inherits:
Object
  • Object
show all
Includes:
Utils::Raisers
Defined in:
lib/wwwjdic/parsers/key.rb

Overview

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

Copyright

© 2014-2021 Marco Bresciani

License

GNU General Public License version 3

Instance Method Summary collapse

Methods included from Utils::Raisers

#raiser_array, #raiser_downcase, #raiser_to_i

Instance Method Details

#parse(value = :english) ⇒ Object

The parsable duck type interface to every parser usage.

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
# File 'lib/wwwjdic/parsers/key.rb', line 71

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