Class: Cucumber::Core::Ast::DocString
- Inherits:
-
Object
- Object
- Cucumber::Core::Ast::DocString
- Includes:
- DescribesItself, HasLocation
- Defined in:
- lib/cucumber/core/ast/doc_string.rb
Overview
Represents an inline argument in a step. Example:
Given the
"""
I like
Cucumber sandwich
"""
The text between the pair of """
is stored inside a DocString, which is yielded to the StepDefinition block as the last argument.
The StepDefinition can then access the String via the #to_s method. In the example above, that would return: "I like\nCucumber sandwich"
Note how the indentation from the source is stripped away.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #encoding ⇒ Object
- #gsub(*args) ⇒ Object
-
#initialize(string, content_type, location) ⇒ DocString
constructor
A new instance of DocString.
- #map ⇒ Object
- #to_s ⇒ Object
- #to_step_definition_arg ⇒ Object
- #to_str ⇒ Object
Methods included from DescribesItself
Methods included from HasLocation
#attributes, #comments, #file_colon_line, #line, #location, #match_locations?, #multiline_arg, #tags
Constructor Details
#initialize(string, content_type, location) ⇒ DocString
Returns a new instance of DocString.
28 29 30 31 32 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 28 def initialize(string, content_type, location) @content = string @content_type = content_type @location = location end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
26 27 28 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 26 def content @content end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
26 27 28 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 26 def content_type @content_type end |
#file ⇒ Object
Returns the value of attribute file.
24 25 26 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 24 def file @file end |
Instance Method Details
#==(other) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 60 def ==(other) if other.respond_to?(:content_type) return false unless content_type == other.content_type end if other.respond_to?(:to_str) return content == other.to_str end raise ArgumentError, "Can't compare a #{self.class.name} with a #{other.class.name}" end |
#encoding ⇒ Object
34 35 36 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 34 def encoding @content.encoding end |
#gsub(*args) ⇒ Object
46 47 48 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 46 def gsub(*args) @content.gsub(*args) end |
#map ⇒ Object
50 51 52 53 54 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 50 def map raise ArgumentError, "No block given" unless block_given? new_content = yield content self.class.new(new_content, content_type, location) end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 42 def to_s to_str end |
#to_step_definition_arg ⇒ Object
56 57 58 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 56 def to_step_definition_arg self end |
#to_str ⇒ Object
38 39 40 |
# File 'lib/cucumber/core/ast/doc_string.rb', line 38 def to_str @content end |