class Xembly::Directives

Directives

Public Class Methods

map(cmd) click to toggle source
# File lib/xembly/directives.rb, line 54
def self.map(cmd)
  args = cmd.drop(1)
  case cmd[0].upcase
  when 'ADD'
    Add.new(args[0])
  when 'ADDIF'
    AddIf.new(args[0])
  when 'ATTR'
    Attr.new(args[0], args[1])
  when 'CDATA'
    raise 'CDATA command is not supported yet, please contribute'
  when 'NS'
    raise 'NS command is not supported yet, please contribute'
  when 'PI'
    raise 'PI command is not supported yet, please contribute'
  when 'POP'
    raise 'POP command is not supported yet, please contribute'
  when 'PUSH'
    raise 'PUSH command is not supported yet, please contribute'
  when 'REMOVE'
    Remove.new
  when 'SET'
    Set.new(args[0])
  when 'STRICT'
    Strict.new(args[0])
  when 'UP'
    Up.new
  when 'XPATH'
    Xpath.new(args[0])
  when 'XSET'
    raise 'XSET command is not supported yet, please contribute'
  else
    raise "Unknown command \"#{cmd}\""
  end
end
new(text) click to toggle source

Ctor.

text

Directives in text

# File lib/xembly/directives.rb, line 38
def initialize(text)
  @array = text
           .strip
           .scan(/([A-Za-z]+)(?:\s+"([^"]+)")?(?:\s*,\s*"([^"]+)")*\s*;/)
           .map { |t| t.reject(&:nil?) }
           .map { |t| Directives.map(t) }
end

Public Instance Methods

each(&block) click to toggle source
# File lib/xembly/directives.rb, line 46
def each(&block)
  @array.each(&block)
end
length() click to toggle source
# File lib/xembly/directives.rb, line 50
def length
  @array.length
end