Module: OTS

Defined in:
lib/ots.rb,
lib/ots/grader.rb,
ext/ots/ots.c

Defined Under Namespace

Classes: Article, Grader

Constant Summary collapse

DICTIONARY_PATH =
File.absolute_path(File.dirname(__FILE__) + '/../dictionaries')
VERSION =
rb_str_new2(RUBY_OTS_VERSION)

Class Method Summary collapse

Class Method Details

.languagesObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'ext/ots/ots.c', line 158

VALUE ots_languages(VALUE self) {
    DIR *dir;
    struct dirent *entry;
    VALUE languages = rb_ary_new();

    if ((dir = opendir(DICTIONARY_DIR))) {
        while ((entry = readdir(dir))) {
            // entry->d_type is not portable.
            if (strstr(entry->d_name, ".xml"))
                rb_ary_push(languages, rb_str_new(entry->d_name, strlen(entry->d_name) - 4));
        }
    }
    else {
        rb_raise(rb_eIOError, "unable to open dictionary directory: %s", strerror(errno));
    }

    closedir(dir);
    return languages;
}

.parse(*args) ⇒ Object



152
153
154
155
156
# File 'ext/ots/ots.c', line 152

VALUE ots_parse(int argc, VALUE *argv, VALUE self) {
    VALUE article = article_allocate(cArticle);
    article_initialize(argc, argv, article);
    return article;
}

.set_dictionary_path(path) ⇒ Object



178
179
180
181
182
183
184
185
186
# File 'ext/ots/ots.c', line 178

VALUE ots_set_dictionary_path(VALUE self, VALUE path) {
    char *string = CSTRING(path);
    if (DICTIONARY_DIR)
        free(DICTIONARY_DIR);

    DICTIONARY_DIR = (char *)malloc(strlen(string) + 2);
    sprintf(DICTIONARY_DIR, "%s/", string);
    return Qnil;
}