class Stanza::Stanza
Attributes
attrs[RW]
comment[RW]
commentChar[RW]
name[RW]
Public Class Methods
new(name, attrs)
click to toggle source
# File lib/Stanza/Stanza.rb, line 8 def initialize(name, attrs) @name = name @attrs = attrs @comment = '' @commentChar = '*' end
Public Instance Methods
addAttribute(name, value)
click to toggle source
# File lib/Stanza/Stanza.rb, line 32 def addAttribute(name, value) @attrs[name] = value end
Also aliased as: setAttribute
addComment(comment)
click to toggle source
# File lib/Stanza/Stanza.rb, line 24 def addComment(comment) @comment += comment + "\n" end
attributes()
click to toggle source
# File lib/Stanza/Stanza.rb, line 44 def attributes @attrs.keys end
Also aliased as: keys
copy(stanza)
click to toggle source
# File lib/Stanza/Stanza.rb, line 15 def copy(stanza) if stanza.kind_of?(Stanza) empty! @attrs = stanza.attrs @comment = stanza.comment @commentChar = stanza.commentChar end end
delAttribute(name)
click to toggle source
# File lib/Stanza/Stanza.rb, line 36 def delAttribute(name) @attrs.delete(name) if attrs.key?(name) end
delComment()
click to toggle source
# File lib/Stanza/Stanza.rb, line 28 def delComment() @comment = '' end
each() { |k, v| ... }
click to toggle source
# File lib/Stanza/Stanza.rb, line 62 def each @attrs.each { |k, v| yield(k, v) } end
Also aliased as: each_pair
each_attribute() { |k| ... }
click to toggle source
# File lib/Stanza/Stanza.rb, line 66 def each_attribute @attrs.each_key { |k| yield(k) } end
each_value() { |v| ... }
click to toggle source
# File lib/Stanza/Stanza.rb, line 70 def each_value @attrs.each_value { |v| yield(v) } end
empty!()
click to toggle source
# File lib/Stanza/Stanza.rb, line 56 def empty! @attrs.clear @name = '' @comment = '' end
Also aliased as: clear!
empty?()
click to toggle source
# File lib/Stanza/Stanza.rb, line 74 def empty? @attrs.empty? end
getAttribute(name)
click to toggle source
# File lib/Stanza/Stanza.rb, line 40 def getAttribute(name) return @attrs[name] if attrs.key?(name) end
has_attribute?(name)
click to toggle source
# File lib/Stanza/Stanza.rb, line 78 def has_attribute?(name) @attrs.has_key(name) end
hash()
click to toggle source
# File lib/Stanza/Stanza.rb, line 52 def hash @attrs end
merge!(otherStanza)
click to toggle source
# File lib/Stanza/Stanza.rb, line 82 def merge!(otherStanza) if otherStanza.kind_of?(Stanza) @attrs.merge!(otherStanza.attrs) @comment += otherStanza.comment end end
to_s()
click to toggle source
# File lib/Stanza/Stanza.rb, line 89 def to_s s = ERB.new("<% @comment.lines do |line| %> <%= @commentChar %> <%= line %> <% end %> <%= @name %>: <% @attrs.each do |key, value| %> <%= key %> = <%= value.chomp %> <% end %> ", 0, '<>').result(binding) return s end
Also aliased as: inspect
values()
click to toggle source
# File lib/Stanza/Stanza.rb, line 48 def values @attrs.values end