Class: LibLouis::BrailleTable
- Inherits:
-
Object
- Object
- LibLouis::BrailleTable
- Defined in:
- ext/liblouis/braille_table.c
Instance Attribute Summary collapse
- #display_name ⇒ Object (also: #to_s) readonly
- #file ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #back_translate(*args) ⇒ Object (also: #get_text)
- #characters_to_dots(input) ⇒ Object
- #compile(rule) ⇒ Object
- #dots_to_characters(input) ⇒ Object
- #emphasis_classes ⇒ Object
- #hyphenate(*args) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #inspect ⇒ Object
- #metadata(key) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'ext/liblouis/braille_table.c', line 65 static VALUE ll_table_initialize(int argc, VALUE *argv, VALUE self) { const ID allowed[] = {id_display_name}; VALUE file; VALUE keywords = Qnil; VALUE display_name = Qundef; rb_scan_args(argc, argv, "1:", &file, &keywords); if (!NIL_P(keywords)) rb_get_kwargs(rb_hash_dup(keywords), allowed, 0, 1, &display_name); return ll_table_finish(self, file, display_name == Qundef ? Qnil : display_name); } |
Instance Attribute Details
#display_name ⇒ Object (readonly) Also known as: to_s
#file ⇒ Object (readonly)
Class Method Details
.all ⇒ Object
142 143 144 145 146 147 |
# File 'ext/liblouis/braille_table.c', line 142 static VALUE ll_table_all(VALUE owner) { (void)owner; return ll_table_list(lou_listTables()); } |
.find(query) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'ext/liblouis/braille_table.c', line 149 static VALUE ll_table_find(VALUE owner, VALUE query) { VALUE string = StringValue(query); char *file = lou_findTable(StringValueCStr(string)); VALUE result; (void)owner; if (!file) return Qnil; result = ll_table_build(rb_utf8_str_new_cstr(file)); lou_freeTableFile(file); return result; } |
.find_all(query) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'ext/liblouis/braille_table.c', line 164 static VALUE ll_table_find_all(VALUE owner, VALUE query) { VALUE string = StringValue(query); (void)owner; return ll_table_list(lou_findTables(StringValueCStr(string))); } |
Instance Method Details
#back_translate(*args) ⇒ Object Also known as: get_text
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'ext/liblouis/translation.c', line 316 static VALUE ll_table_back_translate(int argc, VALUE *argv, VALUE self) { const ID allowed[] = {id_mode}; VALUE input; VALUE keywords = Qnil; VALUE values[1]; VALUE input_storage; VALUE output_storage; int input_length; int translated_input_length; int output_length; int dots_io = 0; int output_capacity; int mode; rb_scan_args(argc, argv, "1:", &input, &keywords); input_storage = ll_back_input_storage(input, &input_length, &dots_io); ll_check_translation_input(input_storage, input_length); ll_get_keywords(keywords, allowed, 1, values); mode = ll_translation_mode(values[0], noUndefined | partialTrans, "back"); if (dots_io) mode |= dotsIO; output_capacity = ll_output_capacity(input_length); for (;;) { translated_input_length = input_length; output_length = output_capacity; output_storage = ll_binary_storage((size_t)output_capacity * sizeof(widechar)); if (!lou_backTranslate( ll_table_name(self), LL_PTR(widechar, input_storage), &translated_input_length, LL_PTR(widechar, output_storage), &output_length, NULL, NULL, NULL, NULL, NULL, mode)) rb_raise(ll_eTranslationError, "back translation failed for table %s", ll_table_name(self)); if (translated_input_length == input_length) break; output_capacity = ll_larger_output_capacity(output_capacity); } return ll_string_from_wide_storage(output_storage, output_length); } |
#characters_to_dots(input) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'ext/liblouis/translation.c', line 390 static VALUE ll_table_characters_to_dots(VALUE self, VALUE input) { VALUE input_storage; VALUE output_storage; int length; input_storage = ll_wide_storage_from_string(input, &length); output_storage = ll_binary_storage((size_t)length * sizeof(widechar)); if (length > 0 && !lou_charToDots(ll_table_name(self), LL_PTR(widechar, input_storage), LL_PTR(widechar, output_storage), length, 0)) rb_raise(ll_eTranslationError, "character-to-dots conversion failed for table %s", ll_table_name(self)); return ll_braille_text_from_dot_storage(output_storage, length); } |
#compile(rule) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'ext/liblouis/braille_table.c', line 102 static VALUE ll_table_compile(VALUE self, VALUE rule) { VALUE string = StringValue(rule); if (!lou_compileString(ll_table_name(self), StringValueCStr(string))) rb_raise(ll_eError, "could not compile Liblouis rule for table %s", ll_table_name(self)); return self; } |
#dots_to_characters(input) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'ext/liblouis/translation.c', line 408 static VALUE ll_table_dots_to_characters(VALUE self, VALUE input) { VALUE input_storage; VALUE output_storage; int length; input_storage = ll_back_input_storage(input, &length, NULL); output_storage = ll_binary_storage((size_t)length * sizeof(widechar)); if (length > 0 && !lou_dotsToChar(ll_table_name(self), LL_PTR(widechar, input_storage), LL_PTR(widechar, output_storage), length, 0)) rb_raise(ll_eTranslationError, "dots-to-character conversion failed for table %s", ll_table_name(self)); return ll_string_from_wide_storage(output_storage, length); } |
#emphasis_classes ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'ext/liblouis/braille_table.c', line 113 static VALUE ll_table_emphasis_classes(VALUE self) { const char **classes = lou_getEmphClasses(ll_table_name(self)); VALUE result = rb_ary_new(); int index; if (!classes) return result; for (index = 0; classes[index]; index++) rb_ary_push(result, ID2SYM(rb_intern(classes[index]))); lou_freeEmphClasses(classes); return result; } |
#hyphenate(*args) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'ext/liblouis/translation.c', line 358 static VALUE ll_table_hyphenate(int argc, VALUE *argv, VALUE self) { const ID allowed[] = {id_translated}; VALUE input; VALUE keywords = Qnil; VALUE values[1]; VALUE input_storage; VALUE hyphens; int input_length; int mode; rb_scan_args(argc, argv, "1:", &input, &keywords); ll_get_keywords(keywords, allowed, 1, values); if (values[0] == Qundef || NIL_P(values[0]) || values[0] == Qfalse) mode = 0; else if (values[0] == Qtrue) mode = 1; else rb_raise(rb_eTypeError, "translated must be true or false"); input_storage = ll_wide_storage_from_string(input, &input_length); hyphens = ll_binary_storage((size_t)input_length + 1); if (!lou_hyphenate(ll_table_name(self), LL_PTR(widechar, input_storage), input_length, RSTRING_PTR(hyphens), mode)) rb_raise(ll_eTranslationError, "hyphenation failed for table %s", ll_table_name(self)); rb_str_resize(hyphens, input_length); rb_enc_associate(hyphens, rb_usascii_encoding()); return hyphens; } |
#inspect ⇒ Object
80 81 82 83 84 85 86 |
# File 'ext/liblouis/braille_table.c', line 80 static VALUE ll_table_inspect(VALUE self) { return rb_sprintf( "#<LibLouis::BrailleTable file=%+"PRIsVALUE" display_name=%+"PRIsVALUE">", ll_table_file(self), rb_ivar_get(self, id_display_name_ivar)); } |
#metadata(key) ⇒ Object
88 89 90 91 92 93 94 |
# File 'ext/liblouis/braille_table.c', line 88 static VALUE (VALUE self, VALUE key) { VALUE string = StringValue(key); return (ll_table_file(self), StringValueCStr(string)); } |
#valid? ⇒ Boolean
96 97 98 99 100 |
# File 'ext/liblouis/braille_table.c', line 96 static VALUE ll_table_valid_p(VALUE self) { return lou_checkTable(ll_table_name(self)) ? Qtrue : Qfalse; } |