Class: QDA::Fragment
- Inherits:
-
String
- Object
- String
- QDA::Fragment
- Includes:
- Coding
- Defined in:
- lib/weft/document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#docid ⇒ Object
Returns the value of attribute docid.
-
#doctitle ⇒ Object
readonly
Returns the value of attribute doctitle.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](abs, length) ⇒ Object
returns a fragment from
abs
(relative to the whole document) that islength
long. - #coerce(other) ⇒ Object
-
#complete? ⇒ Boolean
does this code completely cover the document.
-
#initialize(text, doctitle, offset, docid = nil) ⇒ Fragment
constructor
A new instance of Fragment.
- #inspect ⇒ Object
- #scan(pattern) ⇒ Object
- #text ⇒ Object
- #title ⇒ Object
- #to_code ⇒ Object
Methods included from Coding
#<=>, #end, #exclude, #include?, #intersect, #overlap?, #prepare_args, #touch?, #union
Constructor Details
#initialize(text, doctitle, offset, docid = nil) ⇒ Fragment
Returns a new instance of Fragment.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/weft/document.rb', line 9 def initialize(text, doctitle, offset, docid = nil) super(text) unless doctitle.kind_of? String raise ArgumentError, "Fragment.new expects a doctitle string, got #{doctitle.inspect}" end unless offset.kind_of?(Fixnum) && offset >= 0 raise ArgumentError, "Fragment.new expects an integer offset, got #{offset.inspect}" end unless docid.nil? || docid.kind_of?(Fixnum) raise ArgumentError, "Fragment.new expects an integer docid, got #{docid.inspect}" end @doctitle = doctitle @offset = offset # of the document - duplicates role of doctitle - to fix @docid = docid end |
Instance Attribute Details
#docid ⇒ Object
Returns the value of attribute docid.
7 8 9 |
# File 'lib/weft/document.rb', line 7 def docid @docid end |
#doctitle ⇒ Object (readonly)
Returns the value of attribute doctitle.
6 7 8 |
# File 'lib/weft/document.rb', line 6 def doctitle @doctitle end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
6 7 8 |
# File 'lib/weft/document.rb', line 6 def offset @offset end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 42 43 |
# File 'lib/weft/document.rb', line 39 def ==(other) super(other) and @offset == other.offset and @doctitle == other.doctitle end |
#[](abs, length) ⇒ Object
returns a fragment from abs
(relative to the whole document) that is length
long
64 65 66 67 68 69 70 |
# File 'lib/weft/document.rb', line 64 def [](abs, length) if abs < self.offset raise "Can't get part of non-overlapping string" end Fragment.new( super(abs - self.offset, length), @doctitle, abs, @docid ) end |
#coerce(other) ⇒ Object
49 50 51 |
# File 'lib/weft/document.rb', line 49 def coerce(other) self.to_code() end |
#complete? ⇒ Boolean
does this code completely cover the document
54 55 56 57 58 59 60 |
# File 'lib/weft/document.rb', line 54 def complete?() return NotImplementedError # need to fix if @doc.fragments.length == @length + 1 return true end return false end |
#inspect ⇒ Object
79 80 81 82 |
# File 'lib/weft/document.rb', line 79 def inspect() str = length < 50 ? self.to_s : self.to_s[0, 50] << '...' "<*Fragment #{docid} #{offset}-#{self.end} : '#{str}>" end |
#scan(pattern) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/weft/document.rb', line 72 def scan(pattern) super do | m | yield Fragment.new(m, @doctitle, offset + Regexp.last_match.begin(0), @dbid ) end end |
#text ⇒ Object
35 36 37 |
# File 'lib/weft/document.rb', line 35 def text self.to_s() end |
#title ⇒ Object
31 32 33 |
# File 'lib/weft/document.rb', line 31 def title @doctitle end |