Class: Spider::QueryFuncs::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/spiderfw/model/query_funcs.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Expression

Returns a new instance of Expression.



25
26
27
28
# File 'lib/spiderfw/model/query_funcs.rb', line 25

def initialize(string)
    @string = string
    @replacements = {}
end

Instance Method Details

#[]=(el, replacement) ⇒ Object



34
35
36
# File 'lib/spiderfw/model/query_funcs.rb', line 34

def []=(el, replacement)
    @replacements[el] = replacement
end

#each_elementObject



30
31
32
# File 'lib/spiderfw/model/query_funcs.rb', line 30

def each_element
    @string.scan(/:\w[\w\d\.]+/).each{ |el| yield el[1..-1].to_sym }
end

#to_sObject



38
39
40
41
42
43
44
# File 'lib/spiderfw/model/query_funcs.rb', line 38

def to_s
    str = @string
    @replacements.each do |el, rep|
        str = str.gsub(":#{el}", rep)
    end
    return str
end