Sha256: 6f5971ba343c7bb473d9ad83700132edc51285d86de81f2f1c4604d58a20d1e9

Contents?: true

Size: 925 Bytes

Versions: 5

Compression:

Stored size: 925 Bytes

Contents

class Rtml::Rules::DomTag
  attr_reader :name
  attr_reader :child_tags
  attr_reader :order

  def initialize(name)
    @name = name
    @child_tags = []
    @order = []
  end

  def children
    child_tags.flatten.select { |t| t.kind_of?(String) }
  end

  def minimum(child_name) option_for_child(child_name, :minimum) end
  def maximum(child_name) option_for_child(child_name, :maximum) end

  # compatiblity with Array; see Tml::Dom::Ruleset
  def first
    self
  end

  def ==(a)
    a.kind_of?(String) ? a == name : a.name == name
  end

  def to_s
    name
  end

  private
  def option_for_child(child_name, key)
    child_tags.each do |children|
      charr = children.dup
      options = charr.extract_options!
      unless charr.select { |i| i == child_name }.empty?
        return options[key].to_i
      end
    end
    raise "Element with name '#{child_name}' is not allowed within parent '#{name}'"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rtml-2.0.4 lib/rtml/rules/dom_tag.rb
rtml-2.0.3 lib/rtml/rules/dom_tag.rb
rtml-2.0.2 lib/rtml/rules/dom_tag.rb
rtml-2.0.1 lib/rtml/rules/dom_tag.rb
rtml-2.0.0.alpha.1 lib/rtml/rules/dom_tag.rb