Class: String

Inherits:
Object
  • Object
show all
Defined in:
ext/similar_text/similar_text.c

Instance Method Summary collapse

Instance Method Details

#similar(str2) ⇒ Object

Calculate the similarity between strings.

“Hello, World!”.similar(“Hello, World!”) #=> 100.0

Returns:

  • the percentage of similarity between two strings. Type of value Float from 0.0 to 100.0.



65
66
67
68
69
70
71
72
# File 'ext/similar_text/similar_text.c', line 65

static VALUE t_similar(VALUE str1, VALUE str2)
{
  double percent;

  similar_text(StringValueCStr(str1), StringValueCStr(str2), &percent);

  return rb_float_new(percent);
}

#similar_chars(str2) ⇒ Object

Calculate the similarity between strings.

‘Hello WORLD!’.similar_chars ‘Hello, World!’ #=> 8

Returns:

  • number of matching chars between strings.



81
82
83
84
85
86
87
88
89
# File 'ext/similar_text/similar_text.c', line 81

static VALUE t_similar_chars(VALUE str1, VALUE str2)
{
  double percent;
  int sim;

  sim = similar_text(StringValueCStr(str1), StringValueCStr(str2), &percent);

  return rb_int_new(sim);
}