class Bruhl::Object
Attributes
contents[R]
tag[R]
Public Class Methods
new(contents, tag = nil)
click to toggle source
# File lib/bruhl.rb, line 145 def initialize(contents, tag = nil) @contents = contents @tag = tag ? tag.strip : nil end
Public Instance Methods
==(other)
click to toggle source
# File lib/bruhl.rb, line 187 def ==(other) other.is_a?(self.class) && @contents == other.contents && @tag == other.tag end
empty?()
click to toggle source
# File lib/bruhl.rb, line 150 def empty? @contents.empty? end
fetch(key, default = nil)
click to toggle source
# File lib/bruhl.rb, line 165 def fetch(key, default = nil) results = fetch_all(key) if results.size > 1 fail("Found too many #{key} sections!") elsif results.empty? default else results.first end end
fetch_all(key)
click to toggle source
# File lib/bruhl.rb, line 158 def fetch_all(key) @contents.select do |elem| next unless elem.is_a?(Relation) elem.left.to_s == key end.map(&:right) end
inspect()
click to toggle source
# File lib/bruhl.rb, line 193 def inspect to_s end
only(key)
click to toggle source
# File lib/bruhl.rb, line 176 def only(key) results = fetch_all(key) if results.size > 1 fail("Found too many #{key} sections!") elsif results.empty? fail("Found zero #{key} sections!") else results.first end end
size()
click to toggle source
# File lib/bruhl.rb, line 154 def size @contents.size end
to_s()
click to toggle source
# File lib/bruhl.rb, line 197 def to_s str = contents.map(&:to_s).join(', ') '{' + (@tag ? "#{@tag}: #{str}" : str) + '}' end