Class: Weechat::Line
Overview
This class encapsulates lines like they’re printed in WeeChat.
A line usually consists of a prefix (doesn’t have to) and a text. One can access both parts individually, or call methods on both combined, which means that the method will be first called on the prefix and then on the text part.
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#message ⇒ Object
Returns the value of attribute message.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(prefix, message, details = {}) ⇒ Line
constructor
A new instance of Line.
- #join(delimiter) ⇒ Object
- #method_missing(m, *args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(prefix, message, details = {}) ⇒ Line
Returns a new instance of Line.
44 45 46 |
# File 'lib/weechat/line.rb', line 44 def initialize(prefix, , details = {}) @prefix, @message, @details = prefix, , details end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/weechat/line.rb', line 56 def method_missing(m, *args) rets = [] [prefix, ].each do |var| rets << var.__send__(m, *args) rescue var end [rets[0].empty? ? nil : rets[0], rets[1]].compact.join("\t") end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
43 44 45 |
# File 'lib/weechat/line.rb', line 43 def details @details end |
#message ⇒ Object
Returns the value of attribute message.
42 43 44 |
# File 'lib/weechat/line.rb', line 42 def @message end |
#prefix ⇒ Object
Returns the value of attribute prefix.
41 42 43 |
# File 'lib/weechat/line.rb', line 41 def prefix @prefix end |
Class Method Details
.from_hash(h) ⇒ Object
29 30 31 32 33 |
# File 'lib/weechat/line.rb', line 29 def from_hash(h) prefix = h.delete(:prefix) = h.delete(:message) new(prefix, , h) end |
.parse(line) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/weechat/line.rb', line 10 def parse(line) parts = line.split("\t") case parts.size when 0 parts = ["", ""] when 1 if line =~ /\t(\t+)\Z/ parts << $1 else parts.unshift "" end when 2 else parts = [parts[0], parts[1..-1].join("\t")] end new(*parts) end |