Class: Level

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber-rest-bdd/level.rb

Instance Method Summary collapse

Constructor Details

#initialize(levels) ⇒ Level

Returns a new instance of Level.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cucumber-rest-bdd/level.rb', line 14

def initialize(levels)
    arr = []
    while matches = /^ (?:for|in|on) ([^"]+?)(?: with (?:key|id))? "([^"]*)"/.match(levels)
        levels = levels[matches[0].length, levels.length]
        item = {
            resource: get_resource(matches[1]),
            id: matches[2]
        }
        item[:id] = item[:id].to_i if item[:id].match(/^\d+$/)
        arr.append(item)
    end
    @urls = arr.reverse
end

Instance Method Details

#hashObject



32
33
34
35
36
# File 'lib/cucumber-rest-bdd/level.rb', line 32

def hash
    hash = {}
    @urls.each{ |l| hash[get_field("#{get_field(l[:resource]).singularize}_id")] = l[:id] }
    hash
end

#last_hashObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/cucumber-rest-bdd/level.rb', line 38

def last_hash
    last = @urls.last
    if !last.nil?
        key = get_field("#{get_field(last[:resource]).singularize}_id")
        return {
            key => last[:id]
        }
    end
    return {}
end

#to_sObject



49
50
51
# File 'lib/cucumber-rest-bdd/level.rb', line 49

def to_s
    self.url
end

#urlObject



28
29
30
# File 'lib/cucumber-rest-bdd/level.rb', line 28

def url
    @urls.map{ |l| "#{l[:resource]}/#{l[:id]}/"}.join()
end