Class: Xembly::Directives
- Inherits:
-
Object
- Object
- Xembly::Directives
- Defined in:
- lib/xembly/directives.rb
Overview
Directives
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(text) ⇒ Directives
constructor
Ctor.
- #length ⇒ Object
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 .split(/\s*;\s*/) .reject(&:empty?) .map { |t| Directives.map(t) } end |
Class Method Details
.map(text) ⇒ 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 |
# File 'lib/xembly/directives.rb', line 53 def self.map(text) cmd, tail = text.strip.split(/\s+/, 2) args = (tail.nil? ? '' : tail).strip .scan(/"([^"]+)"/) .flatten .map { |a| a.tr('"', '') } case cmd.upcase when 'ADD' Add.new(args[0]) when 'ADDIF' AddIf.new(args[0]) when 'ATTR' Attr.new(args[0], args[1]) 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]) 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 |
#length ⇒ Object
49 50 51 |
# File 'lib/xembly/directives.rb', line 49 def length @array.length end |