Class: Xembly::Directives

Inherits:
Object
  • Object
show all
Defined in:
lib/xembly/directives.rb

Overview

Directives

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Directives

Ctor.

text

Directives in text



37
38
39
40
41
42
43
# File 'lib/xembly/directives.rb', line 37

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

Class Method Details

.map(cmd) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/xembly/directives.rb', line 53

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'
    fail 'CDATA command is not supported yet, please contribute'
  when 'NS'
    fail 'NS command is not supported yet, please contribute'
  when 'PI'
    fail 'PI command is not supported yet, please contribute'
  when 'POP'
    fail 'POP command is not supported yet, please contribute'
  when 'PUSH'
    fail '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'
    fail 'XSET command is not supported yet, please contribute'
  else
    fail "Unknown command \"#{cmd}\""
  end
end

Instance Method Details

#each(&block) ⇒ Object



45
46
47
# File 'lib/xembly/directives.rb', line 45

def each(&block)
  @array.each(&block)
end

#lengthObject



49
50
51
# File 'lib/xembly/directives.rb', line 49

def length
  @array.length
end