Module: PaloAlto::DSL

Included in:
PaloAlto, PaloAlto, Expression
Defined in:
lib/palo_alto/config.rb

Constant Summary collapse

METHODS =

rubocop:disable Lint/BooleanSymbol

[
:count, :id, :local_name, :namespace_uri,
:string, :concat, :starts_with, :contains, :substring_before,
:substring_after, :substring, :string_length, :normalize_space,
:translate,
:boolean, :not, :true, :false, :lang,
:number, :sum, :floor, :ceiling, :round
].freeze
OPERATORS =
[
%i[equals = ==],
%i[or or |],
%i[and and &],
%i[not_equals != !=],
%i[lte <= <=],
%i[lt < <],
%i[gte >= >=],
%i[gt > >],
%i[plus +],
%i[minus -],
%i[multiply * *],
%i[divide div /],
%i[mod mod %]
].freeze
AXES =
%i[
ancestor ancestor_or_self attribute descendant_or_self
following following_sibling namespace parent preceding
preceding_sibling self
].freeze
UPPERCASE_LETTERS =
'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'.freeze
LOWERCASE_LETTERS =
'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'.freeze

Instance Method Summary collapse

Instance Method Details

#anywhere(*expressions) ⇒ Object



26
27
28
# File 'lib/palo_alto/config.rb', line 26

def anywhere(*expressions)
Expression.new(:anywhere, expressions)
end

#axis(name, *element_names) ⇒ Object



23
24
25
# File 'lib/palo_alto/config.rb', line 23

def axis(name, *element_names)
Expression.new(:axis, current, name, element_names)
end

#binary_operator(name, rhs) ⇒ Object



58
59
60
# File 'lib/palo_alto/config.rb', line 58

def binary_operator(name, rhs)
Expression.new(:binary_operator, name, current, rhs)
end

#child(*expressions) ⇒ Object



20
21
22
# File 'lib/palo_alto/config.rb', line 20

def child(*expressions)
Expression.new(:child, current, expressions)
end

#contains_word(word) ⇒ Object



132
133
134
# File 'lib/palo_alto/config.rb', line 132

def contains_word(word)
function(:concat, ' ', current.normalize_space, ' ').contains(" #{word} ")
end

#css(selector) ⇒ Object



35
36
37
# File 'lib/palo_alto/config.rb', line 35

def css(selector)
Expression.new(:css, current, Literal.new(selector))
end

#currentObject



14
15
16
# File 'lib/palo_alto/config.rb', line 14

def current
Expression.new(:this_node)
end

#descendant(*expressions) ⇒ Object



17
18
19
# File 'lib/palo_alto/config.rb', line 17

def descendant(*expressions)
Expression.new(:descendant, current, expressions)
end

#ends_with(suffix) ⇒ Object



128
129
130
131
# File 'lib/palo_alto/config.rb', line 128

def ends_with(suffix)
function(:substring, current,
function(:'string-length', current).minus(function(:'string-length', suffix)).plus(1)) == suffix
end

#function(name, *arguments) ⇒ Object



38
39
40
# File 'lib/palo_alto/config.rb', line 38

def function(name, *arguments)
Expression.new(:function, name, *arguments)
end

#is(expression) ⇒ Object



55
56
57
# File 'lib/palo_alto/config.rb', line 55

def is(expression)
Expression.new(:is, current, expression)
end

#lastObject



65
66
67
# File 'lib/palo_alto/config.rb', line 65

def last
function(:last)
end

#lowercaseObject



137
138
139
# File 'lib/palo_alto/config.rb', line 137

def lowercase
method(:translate, UPPERCASE_LETTERS, LOWERCASE_LETTERS)
end

#method(name, *arguments) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/palo_alto/config.rb', line 41

def method(name, *arguments)
if name != :not
Expression.new(:function, name, current, *arguments)
else
Expression.new(:function, name, *arguments)
end
end

#next_sibling(*expressions) ⇒ Object



149
150
151
# File 'lib/palo_alto/config.rb', line 149

def next_sibling(*expressions)
axis(:'following-sibling')[1].axis(:self, *expressions)
end

#one_of(*expressions) ⇒ Object



146
147
148
# File 'lib/palo_alto/config.rb', line 146

def one_of(*expressions)
expressions.map { |e| current.equals(e) }.reduce(:or)
end

#parenthesis(arg) ⇒ Object



140
141
142
# File 'lib/palo_alto/config.rb', line 140

def parenthesis(arg)
Expression.new(:parenthesis, arg)
end

#positionObject



68
69
70
# File 'lib/palo_alto/config.rb', line 68

def position
function(:position)
end

#previous_sibling(*expressions) ⇒ Object



152
153
154
# File 'lib/palo_alto/config.rb', line 152

def previous_sibling(*expressions)
axis(:'preceding-sibling')[1].axis(:self, *expressions)
end

#qnameObject



87
88
89
# File 'lib/palo_alto/config.rb', line 87

def qname
method(:name)
end

#relative(*expressions) ⇒ Object



8
9
10
# File 'lib/palo_alto/config.rb', line 8

def relative(*expressions)
Expression.new(:relative, current, expressions)
end

#root(*expressions) ⇒ Object



11
12
13
# File 'lib/palo_alto/config.rb', line 11

def root(*expressions)
Expression.new(:root, current, expressions)
end

#textObject



32
33
34
# File 'lib/palo_alto/config.rb', line 32

def text
Expression.new(:text, current)
end

#union(*expressions) ⇒ Object Also known as: +



61
62
63
# File 'lib/palo_alto/config.rb', line 61

def union(*expressions)
Union.new(*[self, expressions].flatten)
end

#uppercaseObject



143
144
145
# File 'lib/palo_alto/config.rb', line 143

def uppercase
method(:translate, LOWERCASE_LETTERS, UPPERCASE_LETTERS)
end

#where(expression) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/palo_alto/config.rb', line 48

def where(expression)
if expression
Expression.new(:where, current, expression)
else
current
end
end

#xpath_attr(expression) ⇒ Object



29
30
31
# File 'lib/palo_alto/config.rb', line 29

def xpath_attr(expression)
Expression.new(:attribute, current, expression)
end