Class: QDA::Code
Overview
object representing a particular application of a code to a document. Not sure entirely what the use of this class is at the moment - have moved over to using Fragment in preference to save lots of round trips to the database when calculating intersections and so on. All the functionality originally developed in this class now moved to Module Coding
, mixed-in here and by Fragment
. That defines all the union, intersection and exclusion operators (+, %, -)
Instance Attribute Summary collapse
-
#docid ⇒ Object
Returns the value of attribute docid.
-
#length ⇒ Object
Returns the value of attribute length.
-
#offset ⇒ Object
Returns the value of attribute offset.
Instance Method Summary collapse
- #<<(other) ⇒ Object
-
#==(other) ⇒ Object
A
code
is equal toother
if applied to the same document starts at the same point and runs for the same number of characters. -
#[](point, length) ⇒ Object
returns a new code starting from
point
within the whole document andlength
characters long. -
#coerce(other) ⇒ Object
a Code is already its own simplest representation, so never needs to be modified to work with another code-like object.
-
#initialize(docid, offset, length) ⇒ Code
constructor
Create a code applied to the document identified by
docid
, starting at pointoffset
and running forlength
characters. - #inspect ⇒ Object
Methods included from Coding
#<=>, #end, #exclude, #include?, #intersect, #overlap?, #prepare_args, #touch?, #union
Constructor Details
#initialize(docid, offset, length) ⇒ Code
Create a code applied to the document identified by docid
, starting at point offset
and running for length
characters
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/weft/category.rb', line 202 def initialize(docid, offset, length) unless docid.is_a?(Integer) raise ArgumentError, "Bad docid value #{docid} expected integer" end unless offset.is_a?(Integer) and offset >= 0 raise ArgumentError, "Bad offset value #{offset} expected integer >= 0" end unless length.is_a?(Integer) and length > 0 raise ArgumentError, "Bad length value #{length}, should be an integer > 0" end @docid = docid @offset = offset @length = length end |
Instance Attribute Details
#docid ⇒ Object
Returns the value of attribute docid.
199 200 201 |
# File 'lib/weft/category.rb', line 199 def docid @docid end |
#length ⇒ Object
Returns the value of attribute length.
199 200 201 |
# File 'lib/weft/category.rb', line 199 def length @length end |
#offset ⇒ Object
Returns the value of attribute offset.
199 200 201 |
# File 'lib/weft/category.rb', line 199 def offset @offset end |
Instance Method Details
#<<(other) ⇒ Object
235 236 237 |
# File 'lib/weft/category.rb', line 235 def <<(other) @length += other.length end |
#==(other) ⇒ Object
A code
is equal to other
if applied to the same document starts at the same point and runs for the same number of characters
228 229 230 231 232 |
# File 'lib/weft/category.rb', line 228 def ==(other) @docid == other.docid and @offset == other.offset and @length == other.length end |
#[](point, length) ⇒ Object
returns a new code starting from point
within the whole document and length
characters long.
241 242 243 |
# File 'lib/weft/category.rb', line 241 def [](point, length) Code.new(@docid, point, length) end |
#coerce(other) ⇒ Object
a Code is already its own simplest representation, so never needs to be modified to work with another code-like object.
222 223 224 |
# File 'lib/weft/category.rb', line 222 def coerce(other) self end |
#inspect ⇒ Object
245 246 247 |
# File 'lib/weft/category.rb', line 245 def inspect "#<QDA::Code [#{@docid}]: #{@offset}-#{self.end}>" end |