Class: Kabosu::Dictionary
- Inherits:
-
Object
- Object
- Kabosu::Dictionary
- Defined in:
- lib/kabosu.rb
Overview
── Dictionary: keyword API and management ──
Class Method Summary collapse
- ._new ⇒ Object
- .install(edition = "core", version: nil) ⇒ Object
- .list ⇒ Object
- .new(config: nil, system_dict: nil, user_dicts: nil) ⇒ Object
- .path(edition: nil) ⇒ Object
Instance Method Summary collapse
Class Method Details
._new ⇒ Object
55 |
# File 'lib/kabosu.rb', line 55 alias_method :_new, :new |
.install(edition = "core", version: nil) ⇒ Object
79 80 81 |
# File 'lib/kabosu.rb', line 79 def install(edition = "core", version: nil) dict_manager.install(edition, version: version) end |
.list ⇒ Object
87 88 89 |
# File 'lib/kabosu.rb', line 87 def list dict_manager.installed end |
.new(config: nil, system_dict: nil, user_dicts: nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kabosu.rb', line 57 def new(config: nil, system_dict: nil, user_dicts: nil) unless config.nil? || config.is_a?(String) raise ArgumentError, "config must be a String or nil" end unless system_dict.nil? || system_dict.is_a?(String) raise ArgumentError, "system_dict must be a String or nil" end unless user_dicts.nil? || user_dicts.is_a?(Array) raise ArgumentError, "user_dicts must be an Array<String> or nil" end if user_dicts&.any? { !_1.is_a?(String) } raise ArgumentError, "user_dicts must contain only String values" end if config.nil? && system_dict.nil? raise ArgumentError, "either config or system_dict is required" end _new(config, system_dict, user_dicts) rescue RuntimeError => e raise map_dictionary_init_error(e, config: config, system_dict: system_dict) end |
.path(edition: nil) ⇒ Object
83 84 85 |
# File 'lib/kabosu.rb', line 83 def path(edition: nil) dict_manager.find(edition: edition) end |
Instance Method Details
#_create ⇒ Object
109 |
# File 'lib/kabosu.rb', line 109 alias_method :_create, :create |
#_lookup ⇒ Object
110 |
# File 'lib/kabosu.rb', line 110 alias_method :_lookup, :lookup |
#create(**options) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/kabosu.rb', line 112 def create(**) unknown = .keys - %i[mode fields debug projection] raise ArgumentError, "unknown keyword(s): #{unknown.join(', ')}" unless unknown.empty? mode = .fetch(:mode, MODE_C) fields = .fetch(:fields, nil) debug = .fetch(:debug, false) projection = .fetch(:projection, nil) unless fields.nil? || fields.is_a?(Array) raise ArgumentError, "fields must be an Array<String|Symbol> or nil" end if fields&.any? { !(_1.is_a?(String) || _1.is_a?(Symbol)) } raise ArgumentError, "fields must contain only String or Symbol values" end unless debug == true || debug == false raise ArgumentError, "debug must be true or false" end unless projection.nil? raise NotImplementedError, "projection is not supported yet" end mode_str = Kabosu.__send__(:normalize_mode, mode) _create(mode_str, fields, debug) end |
#lookup(text) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/kabosu.rb', line 139 def lookup(text) unless text.is_a?(String) raise ArgumentError, "text must be a String" end MorphemeList.new(_lookup(text)) rescue RuntimeError => e raise LookupError.new(e.), cause: e end |