Class: Lumix::TextSnippet
- Inherits:
-
Object
- Object
- Lumix::TextSnippet
- Defined in:
- lib/lumix/text_snippet.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
cleanup($1).
-
#initialize(name, text, first, last) ⇒ TextSnippet
constructor
A new instance of TextSnippet.
- #left(context = 5) ⇒ Object
-
#right(context = 5) ⇒ Object
cleanup($1).
- #to_s ⇒ Object
Constructor Details
#initialize(name, text, first, last) ⇒ TextSnippet
Returns a new instance of TextSnippet.
5 6 7 8 9 10 |
# File 'lib/lumix/text_snippet.rb', line 5 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.
4 5 6 |
# File 'lib/lumix/text_snippet.rb', line 4 def begin @begin end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
4 5 6 |
# File 'lib/lumix/text_snippet.rb', line 4 def end @end end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/lumix/text_snippet.rb', line 4 def name @name end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
4 5 6 |
# File 'lib/lumix/text_snippet.rb', line 4 def text @text end |
Instance Method Details
#cleanup(txt) ⇒ Object
cleanup($1)
24 25 26 |
# File 'lib/lumix/text_snippet.rb', line 24 def cleanup(txt) txt.gsub(/\s+/, ' ') end |
#left(context = 5) ⇒ Object
14 15 16 17 18 |
# File 'lib/lumix/text_snippet.rb', line 14 def left(context = 5) ctx = [@begin - context * 10, 0].max @text[ctx...@begin].split(/\s+/).last(context).join(' ')# =~ /((\S+\s+){0,#{context}}\S*)\z/m #cleanup($1) end |
#right(context = 5) ⇒ Object
cleanup($1)
19 20 21 22 23 |
# File 'lib/lumix/text_snippet.rb', line 19 def right(context = 5) ctx = [@end + context * 10, @text.size].min @text[@end..ctx].split(/\s+/).first(context).join(' ')# =~ /\A(\S*(\s+\S+){0,#{context}})/m #cleanup($1) end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/lumix/text_snippet.rb', line 11 def to_s cleanup(@text[@begin...@end]) end |