Class: Butler::Plugin::More

Inherits:
Object
  • Object
show all
Defined in:
lib/butler/plugin/more.rb

Constant Summary collapse

MessageLength =
500
String =
{
	"en" => "![c(white),(black)]more...![o]".mirc_formatted,
	"de" => "![c(white),(black)]mehr...![o]".mirc_formatted,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, lead, text) ⇒ More

Returns a new instance of More.



23
24
25
26
27
28
29
30
31
# File 'lib/butler/plugin/more.rb', line 23

def initialize(message, lead, text)
	@language = message.language
	@lead     = !lead || lead.empty? ? nil : lead
	@text     = text
	@index    = 0
	chunks    = MessageLength-(lead ? lead.length+4 : 2)-tail.length
	@pieces   = text.scan(/.{1,#{chunks}}(?:\b|$)/m)
	@length   = @pieces.length
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



20
21
22
# File 'lib/butler/plugin/more.rb', line 20

def index
  @index
end

#leadObject (readonly)

Returns the value of attribute lead.



18
19
20
# File 'lib/butler/plugin/more.rb', line 18

def lead
  @lead
end

#lengthObject (readonly)

Returns the value of attribute length.



21
22
23
# File 'lib/butler/plugin/more.rb', line 21

def length
  @length
end

#textObject (readonly)

Returns the value of attribute text.



19
20
21
# File 'lib/butler/plugin/more.rb', line 19

def text
  @text
end

Instance Method Details

#currentObject



51
52
53
# File 'lib/butler/plugin/more.rb', line 51

def current
	@pieces[@index]
end

#prevObject



38
39
40
41
# File 'lib/butler/plugin/more.rb', line 38

def prev
	raise "Reached start already" if @index.zero?
	@pieces[@index-=1]
end

#prev?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/butler/plugin/more.rb', line 47

def prev?
	!@index.zero?
end

#showObject

show adds lead and tail depending on requirement (no tail for last message, no lead if empty)



56
57
58
# File 'lib/butler/plugin/more.rb', line 56

def show
	"#{lead+': ' if lead}#{@pieces[@index]}#{' '+tail if succ?}"
end

#succObject



33
34
35
36
# File 'lib/butler/plugin/more.rb', line 33

def succ
	raise "Reached end already" if @index+1 >= @length
	@pieces[@index+=1]
end

#succ?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/butler/plugin/more.rb', line 43

def succ?
	@index+1 < @length
end

#tailObject



60
61
62
# File 'lib/butler/plugin/more.rb', line 60

def tail
	String[@language] || String["en"]
end