Class: Cucumber::Messages::Rule

Inherits:
Message
  • Object
show all
Defined in:
lib/cucumber/messages/rule.rb

Overview

Represents the Rule message in Cucumber’s message protocol.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

camelize, from_json, #to_h, #to_json

Constructor Details

#initialize(location: Location.new, tags: [], keyword: '', name: '', description: '', children: [], id: '') ⇒ Rule

Returns a new instance of Rule.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cucumber/messages/rule.rb', line 31

def initialize(
  location: Location.new,
  tags: [],
  keyword: '',
  name: '',
  description: '',
  children: [],
  id: ''
)
  @location = location
  @tags = tags
  @keyword = keyword
  @name = name
  @description = description
  @children = children
  @id = id
  super()
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



27
28
29
# File 'lib/cucumber/messages/rule.rb', line 27

def children
  @children
end

#descriptionObject (readonly)

Returns the value of attribute description.



25
26
27
# File 'lib/cucumber/messages/rule.rb', line 25

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



29
30
31
# File 'lib/cucumber/messages/rule.rb', line 29

def id
  @id
end

#keywordObject (readonly)

Returns the value of attribute keyword.



21
22
23
# File 'lib/cucumber/messages/rule.rb', line 21

def keyword
  @keyword
end

#locationObject (readonly)

The location of the ‘Rule` keyword



14
15
16
# File 'lib/cucumber/messages/rule.rb', line 14

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/cucumber/messages/rule.rb', line 23

def name
  @name
end

#tagsObject (readonly)

All the tags placed above the ‘Rule` keyword



19
20
21
# File 'lib/cucumber/messages/rule.rb', line 19

def tags
  @tags
end

Class Method Details

.from_h(hash) ⇒ Object

Returns a new Rule from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.

Cucumber::Messages::Rule.from_h(some_hash) # => #<Cucumber::Messages::Rule:0x... ...>


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cucumber/messages/rule.rb', line 57

def self.from_h(hash)
  return nil if hash.nil?

  new(
    location: Location.from_h(hash[:location]),
    tags: hash[:tags]&.map { |item| Tag.from_h(item) },
    keyword: hash[:keyword],
    name: hash[:name],
    description: hash[:description],
    children: hash[:children]&.map { |item| RuleChild.from_h(item) },
    id: hash[:id]
  )
end