Class: Hector::Response
- Inherits:
-
Object
- Object
- Hector::Response
- Defined in:
- lib/hector/response.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #event_name ⇒ Object
-
#initialize(command, *args) ⇒ Response
constructor
A new instance of Response.
- #to_s ⇒ Object
Constructor Details
#initialize(command, *args) ⇒ Response
Returns a new instance of Response.
26 27 28 29 30 31 32 33 34 |
# File 'lib/hector/response.rb', line 26 def initialize(command, *args) @command = command.to_s.upcase @args = args = args.pop if args.last.is_a?(Hash) @text = [:text] if @source = [:source] if @source ||= Hector.server_name if @command =~ /^\d+$/ end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/hector/response.rb', line 3 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
3 4 5 |
# File 'lib/hector/response.rb', line 3 def command @command end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/hector/response.rb', line 3 def source @source end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/hector/response.rb', line 4 def text @text end |
Class Method Details
.apportion_text(args, *base_args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hector/response.rb', line 7 def apportion_text(args, *base_args) base_response = Response.new(*base_args) max_length = 510 - base_response.to_s.bytesize args.inject([args.shift.dup]) do |texts, arg| if texts.last.bytesize + arg.bytesize + 1 >= max_length texts << arg.dup else texts.last << " " << arg end texts end.map do |text| base_response.dup.tap do |response| response.text = text end end end |
Instance Method Details
#event_name ⇒ Object
36 37 38 |
# File 'lib/hector/response.rb', line 36 def event_name "received_#{command.downcase}" end |
#to_s ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hector/response.rb', line 40 def to_s [].tap do |line| line.push(":#{source}") if source line.push(command) line.concat(args) line.push(":#{text}") if text end.map do |arg| if arg.respond_to?(:force_encoding) then arg.force_encoding("UTF-8") else arg end end.join(" ")[0, 510] + "\r\n" end |