Class: Redwood::Container
Overview
recursive structure used internally to represent message trees as described by reply-to: and references: headers.
the ‘id’ field is the same as the message id. but the message might be empty, in the case that we represent a message that was referenced by another message (as an ancestor) but never received.
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #date ⇒ Object
- #descendant_of?(o) ⇒ Boolean
- #dump_recursive(f = $stdout, indent = 0, root = true, parent = nil) ⇒ Object
- #each_with_stuff(parent = nil) {|_self, 0, parent| ... } ⇒ Object
- #empty? ⇒ Boolean
- #find_attr(attr) ⇒ Object
-
#first_useful_descendant ⇒ Object
skip over any containers which are empty and have only one child.
-
#initialize(id) ⇒ Container
constructor
A new instance of Container.
- #is_reply? ⇒ Boolean
- #root ⇒ Object
- #root? ⇒ Boolean
- #sort_key ⇒ Object
- #subj ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
166 167 168 |
# File 'lib/sup/thread.rb', line 166 def children @children end |
#id ⇒ Object
Returns the value of attribute id.
166 167 168 |
# File 'lib/sup/thread.rb', line 166 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
166 167 168 |
# File 'lib/sup/thread.rb', line 166 def @message end |
#parent ⇒ Object
Returns the value of attribute parent.
166 167 168 |
# File 'lib/sup/thread.rb', line 166 def parent @parent end |
#thread ⇒ Object
Returns the value of attribute thread.
166 167 168 |
# File 'lib/sup/thread.rb', line 166 def thread @thread end |
Instance Method Details
#==(o) ⇒ Object
190 |
# File 'lib/sup/thread.rb', line 190 def == o; Container === o && id == o.id; end |
#date ⇒ Object
216 |
# File 'lib/sup/thread.rb', line 216 def date; find_attr :date; end |
#descendant_of?(o) ⇒ Boolean
182 183 184 185 186 187 188 |
# File 'lib/sup/thread.rb', line 182 def descendant_of? o if o == self true else @parent && @parent.descendant_of?(o) end end |
#dump_recursive(f = $stdout, indent = 0, root = true, parent = nil) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/sup/thread.rb', line 227 def dump_recursive f=$stdout, indent=0, root=true, parent=nil raise "inconsistency" unless parent.nil? || parent.children.include?(self) unless root f.print " " * indent f.print "+->" end line = "[#{thread.nil? ? ' ' : '*'}] " + #"[#{useful? ? 'U' : ' '}] " + if @message .subj ##{@message.refs.inspect} / #{@message.replytos.inspect}" else "<no message>" end f.puts "#{id} #{line}"#[0 .. (105 - indent)] indent += 3 @children.each { |c| c.dump_recursive f, indent, false, self } end |
#each_with_stuff(parent = nil) {|_self, 0, parent| ... } ⇒ Object
175 176 177 178 179 180 |
# File 'lib/sup/thread.rb', line 175 def each_with_stuff parent=nil yield self, 0, parent @children.sort_by(&:sort_key).each do |c| c.each_with_stuff(self) { |cc, d, par| yield cc, d + 1, par } end end |
#empty? ⇒ Boolean
192 |
# File 'lib/sup/thread.rb', line 192 def empty?; @message.nil?; end |
#find_attr(attr) ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/sup/thread.rb', line 208 def find_attr attr if empty? @children.argfind { |c| c.find_attr attr } else @message.send attr end end |
#first_useful_descendant ⇒ Object
skip over any containers which are empty and have only one child. we use this make the threaded display a little nicer, and only stick in the “missing message” line when it’s graphically necessary, i.e. when the missing message has more than one descendent.
200 201 202 203 204 205 206 |
# File 'lib/sup/thread.rb', line 200 def first_useful_descendant if empty? && @children.size == 1 @children.first.first_useful_descendant else self end end |
#is_reply? ⇒ Boolean
218 |
# File 'lib/sup/thread.rb', line 218 def is_reply?; subj && Message.subj_is_reply?(subj); end |
#root? ⇒ Boolean
193 |
# File 'lib/sup/thread.rb', line 193 def root?; @parent.nil?; end |
#sort_key ⇒ Object
245 246 247 |
# File 'lib/sup/thread.rb', line 245 def sort_key empty? ? [Time.now.to_i, ""] : [@message.date.to_i, @message.id] end |
#subj ⇒ Object
215 |
# File 'lib/sup/thread.rb', line 215 def subj; find_attr :subj; end |
#to_s ⇒ Object
220 221 222 223 224 225 |
# File 'lib/sup/thread.rb', line 220 def to_s [ "<#{id}", (@parent.nil? ? nil : "parent=#{@parent.id}"), (@children.empty? ? nil : "children=#{@children.map { |c| c.id }.inspect}"), ].compact.join(" ") + ">" end |