Class: Ferret::Index::TermBuffer

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ferret/index/term_buffer.rb,
ext/term_buffer.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

Methods



35
36
37
38
39
# File 'ext/term_buffer.c', line 35

def initialize
  @text = String.new
  @text_length = -1
  @field = nil
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



60
61
62
# File 'ext/term_buffer.c', line 60

def field
  @field
end

#textObject (readonly)

Returns the value of attribute text.



51
52
53
# File 'ext/term_buffer.c', line 51

def text
  @text
end

#text_lengthObject (readonly)

Returns the value of attribute text_length.



42
43
44
# File 'ext/term_buffer.c', line 42

def text_length
  @text_length
end

Instance Method Details

#<(rother) ⇒ Object



125
126
127
128
129
# File 'ext/term_buffer.c', line 125

VALUE
frt_termbuffer_lt(VALUE self, VALUE rother)
{
  return frt_termbuffer_compare_to_int(self, rother) < 0 ? Qtrue : Qfalse;
}

#<=(rother) ⇒ Object



137
138
139
140
141
# File 'ext/term_buffer.c', line 137

VALUE
frt_termbuffer_le(VALUE self, VALUE rother)
{
  return frt_termbuffer_compare_to_int(self, rother) <= 0 ? Qtrue : Qfalse;
}

#<=>(rother) ⇒ Object



157
158
159
160
161
162
# File 'ext/term_buffer.c', line 157

def <=>(other) 
  if (@field == other.field)
    return text_str <=> other.text_str
  end
  @field <=> other.field
end

#==(rother) ⇒ Object



149
150
151
152
153
154
155
# File 'ext/term_buffer.c', line 149

VALUE
frt_termbuffer_eq(VALUE self, VALUE rother)
{
  if (rother == Qnil)
    return Qfalse;
  return frt_termbuffer_compare_to_int(self, rother) == 0 ? Qtrue : Qfalse;
}

#>(rother) ⇒ Object



131
132
133
134
135
# File 'ext/term_buffer.c', line 131

VALUE
frt_termbuffer_gt(VALUE self, VALUE rother)
{
  return frt_termbuffer_compare_to_int(self, rother) > 0 ? Qtrue : Qfalse;
}

#>=(rother) ⇒ Object



143
144
145
146
147
# File 'ext/term_buffer.c', line 143

VALUE
frt_termbuffer_ge(VALUE self, VALUE rother)
{
  return frt_termbuffer_compare_to_int(self, rother) >= 0 ? Qtrue : Qfalse;
}

#eql?(rother) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
152
153
154
155
# File 'ext/term_buffer.c', line 149

VALUE
frt_termbuffer_eq(VALUE self, VALUE rother)
{
  if (rother == Qnil)
    return Qfalse;
  return frt_termbuffer_compare_to_int(self, rother) == 0 ? Qtrue : Qfalse;
}

#hashObject



252
253
254
# File 'ext/term_buffer.c', line 252

def hash()
  return @text.hash + @field.hash
end

#initialize_copy(rother) ⇒ Object



192
193
194
# File 'ext/term_buffer.c', line 192

def initialize_copy(o)
  set!(o)
end

#read(input, info) ⇒ Object



220
221
222
223
224
225
226
227
228
# File 'ext/term_buffer.c', line 220

def read(input, field_infos)
  @term = nil                           # invalidate cache
  start = input.read_vint()
  length = input.read_vint()
  total_length = start + length
  @text_length = total_length
  input.read_chars(@text, start, length)
  @field = field_infos[input.read_vint()].name
end

#resetObject



69
70
71
72
73
74
# File 'ext/term_buffer.c', line 69

def reset() 
  @field = nil
  @text = String.new
  @text_length = 0
  @term = nil
end

#set!(rother) ⇒ Object



192
193
194
195
196
197
# File 'ext/term_buffer.c', line 192

def set!(other) 
  @text_length = other.text_length
  @text = other.text.clone if other.text
  @field = other.field
  @term = other.term
end

#term=(rterm) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'ext/term_buffer.c', line 163

def term=(term) 
  if (term == nil) 
    reset()
    return
  end

  # copy text into the buffer
  @text_length = term.text.length
  @text = term.text.clone

  @field = term.field
  @term = term
end

#text_strObject



51
52
53
# File 'ext/term_buffer.c', line 51

def text_str()
  @text[0,@text_length]
end

#to_sObject



82
83
84
# File 'lib/ferret/index/term_buffer.rb', line 82

def to_s()
  to_term.to_s
end

#to_termObject Also known as: term



83
84
85
86
87
88
89
90
91
92
# File 'ext/term_buffer.c', line 83

def to_term() 
  if @field.nil?                            # unset
    return nil
  end

  if @term.nil?
    @term = Term.new(@field, @text[0,@text_length].to_s)
  end
  return @term
end