Class: TextSnippet
- Inherits:
-
Object
- Object
- TextSnippet
- Defined in:
- lib/lumix/concordancer.rb
Instance Attribute Summary collapse
-
#begin ⇒ Object
readonly
Returns the value of attribute begin.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #cleanup(txt) ⇒ Object
-
#initialize(name, text, first, last) ⇒ TextSnippet
constructor
A new instance of TextSnippet.
- #left(context = 5) ⇒ Object
- #right(context = 5) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, text, first, last) ⇒ TextSnippet
Returns a new instance of TextSnippet.
26 27 28 29 30 31 |
# File 'lib/lumix/concordancer.rb', line 26 def initialize(name, text, first, last) @name = name @text = text @begin = first @end = last end |
Instance Attribute Details
#begin ⇒ Object (readonly)
Returns the value of attribute begin.
25 26 27 |
# File 'lib/lumix/concordancer.rb', line 25 def begin @begin end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
25 26 27 |
# File 'lib/lumix/concordancer.rb', line 25 def end @end end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/lumix/concordancer.rb', line 25 def name @name end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
25 26 27 |
# File 'lib/lumix/concordancer.rb', line 25 def text @text end |
Instance Method Details
#cleanup(txt) ⇒ Object
43 44 45 |
# File 'lib/lumix/concordancer.rb', line 43 def cleanup(txt) txt.gsub(/\s+/, ' ') end |
#left(context = 5) ⇒ Object
35 36 37 38 |
# File 'lib/lumix/concordancer.rb', line 35 def left(context = 5) @text[0...@begin] =~ /((\S+\s+){0,#{context}}\S*)\z/m cleanup($1) end |
#right(context = 5) ⇒ Object
39 40 41 42 |
# File 'lib/lumix/concordancer.rb', line 39 def right(context = 5) @text[@end..-1] =~ /\A(\S*(\s+\S+){0,#{context}})/m cleanup($1) end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/lumix/concordancer.rb', line 32 def to_s cleanup(@text[@begin...@end]) end |