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



32
33
34
35
36
37
38
# File 'lib/xembly/directives.rb', line 32

def initialize(text)
  @array = text
    .strip
    .split(/\s*;\s*/)
    .reject(&:empty?)
    .map { |t| Directives.map(t) }
end

Class Method Details

.map(text) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/xembly/directives.rb', line 48

def self.map(text)
  cmd, tail = text.strip.split(/\s+/, 2)
  args = tail.strip
    .scan(/"([^"]+)"/)
    .flatten
    .map { |a| a.tr('"', '') }
  case cmd.upcase
  when 'ADD'
    Add.new(args[0])
  when 'ATTR'
    Attr.new(args[0], args[1])
  when 'XPATH'
    Xpath.new(args[0])
  else
    fail "Unknown command \"#{cmd}\""
  end
end

Instance Method Details

#each(&block) ⇒ Object



40
41
42
# File 'lib/xembly/directives.rb', line 40

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

#lengthObject



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

def length
  @array.length
end