Class: TextSnippet

Inherits:
Object
  • Object
show all
Defined in:
lib/lumix/concordancer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#beginObject (readonly)

Returns the value of attribute begin.



25
26
27
# File 'lib/lumix/concordancer.rb', line 25

def begin
  @begin
end

#endObject (readonly)

Returns the value of attribute end.



25
26
27
# File 'lib/lumix/concordancer.rb', line 25

def end
  @end
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/lumix/concordancer.rb', line 25

def name
  @name
end

#textObject (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_sObject



32
33
34
# File 'lib/lumix/concordancer.rb', line 32

def to_s
  cleanup(@text[@begin...@end])
end