Class: Butler::Plugin::More
- Inherits:
-
Object
- Object
- Butler::Plugin::More
- 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
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#lead ⇒ Object
readonly
Returns the value of attribute lead.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize(message, lead, text) ⇒ More
constructor
A new instance of More.
- #prev ⇒ Object
- #prev? ⇒ Boolean
-
#show ⇒ Object
show adds lead and tail depending on requirement (no tail for last message, no lead if empty).
- #succ ⇒ Object
- #succ? ⇒ Boolean
- #tail ⇒ Object
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(, lead, text) @language = .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
#index ⇒ Object (readonly)
Returns the value of attribute index.
20 21 22 |
# File 'lib/butler/plugin/more.rb', line 20 def index @index end |
#lead ⇒ Object (readonly)
Returns the value of attribute lead.
18 19 20 |
# File 'lib/butler/plugin/more.rb', line 18 def lead @lead end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
21 22 23 |
# File 'lib/butler/plugin/more.rb', line 21 def length @length end |
#text ⇒ Object (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
#current ⇒ Object
51 52 53 |
# File 'lib/butler/plugin/more.rb', line 51 def current @pieces[@index] end |
#prev ⇒ Object
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
47 48 49 |
# File 'lib/butler/plugin/more.rb', line 47 def prev? !@index.zero? end |
#show ⇒ Object
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 |
#succ ⇒ Object
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
43 44 45 |
# File 'lib/butler/plugin/more.rb', line 43 def succ? @index+1 < @length end |