class Interscript::Node::Item::Group

Attributes

children[RW]

Public Class Methods

new(*children) click to toggle source
# File lib/interscript/node/item/group.rb, line 4
def initialize *children
  @children = children.flatten.map do |i|
    Interscript::Node::Item.try_convert(i)
  end
end

Public Instance Methods

+(item) click to toggle source
# File lib/interscript/node/item/group.rb, line 10
def +(item)
  item = Interscript::Node::Item.try_convert(item)
  out = self.dup
  if Interscript::Node::Item::Group === item
    out.children += item.children
  else
    out.children << item
  end
  out.verify!
  out
end
==(other) click to toggle source
Calls superclass method Interscript::Node::Item#==
# File lib/interscript/node/item/group.rb, line 72
def ==(other)
  super && self.children == other.children
end
compact() click to toggle source
# File lib/interscript/node/item/group.rb, line 22
def compact
  out = self.dup do |n|
    n.children = n.children.reject do |i|
      (Interscript::Node::Alias === i && i.name == :none) ||
      (Interscript::Node::String === i && i.data == "")
    end
  end

  if out.children.count == 0
    Interscript::Node::Alias.new(:none)
  elsif out.children.count == 1
    out.children.first
  else
    out
  end
end
downcase() click to toggle source
# File lib/interscript/node/item/group.rb, line 39
def downcase; self.dup.tap { |i| i.children = i.children.map(&:downcase) }; end
first_string() click to toggle source
# File lib/interscript/node/item/group.rb, line 55
def first_string
  self.children.map(&:first_string).reduce(&:+)
end
inspect() click to toggle source
# File lib/interscript/node/item/group.rb, line 76
def inspect
  @children.map(&:inspect).join("+")
end
max_length() click to toggle source
# File lib/interscript/node/item/group.rb, line 63
def max_length
  @children.map { |i| i.max_length }.sum
end
nth_string() click to toggle source
# File lib/interscript/node/item/group.rb, line 59
def nth_string
  self.children.map(&:nth_string).reduce(&:+)
end
to_hash() click to toggle source
# File lib/interscript/node/item/group.rb, line 67
def to_hash
  { :class => self.class.to_s,
    :children => self.children.map{|x| x.to_hash} }
end
to_html(doc) click to toggle source
# File lib/interscript/visualize/nodes.rb, line 58
def to_html(doc)
  @children.map{|i|i.to_html(doc)}.join(" + ")
end
upcase() click to toggle source
# File lib/interscript/node/item/group.rb, line 40
def upcase; self.dup.tap { |i| i.children = i.children.map(&:upcase) }; end
verify!() click to toggle source

Verify if a group is valid

# File lib/interscript/node/item/group.rb, line 43
def verify!
  wrong = @children.find do |i|
    Interscript::Node::Item::Stage === i ||
    ! (Interscript::Node::Item === i) ||
    i.class == Interscript::Node::Item
  end

  if wrong
    raise TypeError, "An I::Node::Item::Group can't contain an #{wrong.class} item."
  end
end