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
38 39 40 41 42 43 44 |
# File 'lib/xembly/directives.rb', line 38 def initialize(text) @array = text .strip .scan(/([A-Za-z]+)(?:\s+"([^"]+)")?(?:\s*,\s*"([^"]+)")*\s*;/) .map(&:compact) .map { |t| Directives.map(t) } end |
Class Method Details
.map(cmd) ⇒ Object
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 88 |
# 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 |
Instance Method Details
#each(&block) ⇒ Object
46 47 48 |
# File 'lib/xembly/directives.rb', line 46 def each(&block) @array.each(&block) end |
#length ⇒ Object
50 51 52 |
# File 'lib/xembly/directives.rb', line 50 def length @array.length end |