Class: Level
- Inherits:
-
Object
- Object
- Level
- Defined in:
- lib/cucumber-rest-bdd/level.rb
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(levels) ⇒ Level
constructor
A new instance of Level.
- #last_hash ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
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
#hash ⇒ Object
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_hash ⇒ Object
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_s ⇒ Object
49 50 51 |
# File 'lib/cucumber-rest-bdd/level.rb', line 49 def to_s self.url end |
#url ⇒ Object
28 29 30 |
# File 'lib/cucumber-rest-bdd/level.rb', line 28 def url @urls.map{ |l| "#{l[:resource]}/#{l[:id]}/"}.join() end |