Class: Gherkin::GherkinLine
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb
Defined Under Namespace
Classes: Span
Instance Attribute Summary collapse
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#trimmed_line_text ⇒ Object
readonly
Returns the value of attribute trimmed_line_text.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #get_line_text(indent_to_remove) ⇒ Object
- #get_rest_trimmed(length) ⇒ Object
-
#initialize(line_text, line_number) ⇒ GherkinLine
constructor
A new instance of GherkinLine.
- #split_table_cells(row) ⇒ Object
- #start_with?(prefix) ⇒ Boolean
- #start_with_title_keyword?(keyword) ⇒ Boolean
- #table_cells ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(line_text, line_number) ⇒ GherkinLine
Returns a new instance of GherkinLine.
4 5 6 7 8 9 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 4 def initialize(line_text, line_number) @line_text = line_text @line_number = line_number @trimmed_line_text = @line_text.lstrip @indent = @line_text.length - @trimmed_line_text.length end |
Instance Attribute Details
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
3 4 5 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 3 def indent @indent end |
#trimmed_line_text ⇒ Object (readonly)
Returns the value of attribute trimmed_line_text.
3 4 5 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 3 def trimmed_line_text @trimmed_line_text end |
Instance Method Details
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 23 def empty? @trimmed_line_text.empty? end |
#get_line_text(indent_to_remove) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 27 def get_line_text(indent_to_remove) indent_to_remove ||= 0 if indent_to_remove < 0 || indent_to_remove > indent @trimmed_line_text else @line_text[indent_to_remove..-1] end end |
#get_rest_trimmed(length) ⇒ Object
19 20 21 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 19 def get_rest_trimmed(length) @trimmed_line_text[length..-1].strip end |
#split_table_cells(row) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 51 def split_table_cells(row) col = 0 start_col = col + 1 cell = '' first_cell = true while col < row.length char = row[col] col += 1 if char == '|' if first_cell # First cell (content before the first |) is skipped first_cell = false else yield cell, start_col end cell = '' start_col = col + 1 elsif char == '\\' char = row[col] col += 1 if char == 'n' cell += "\n" else cell += '\\' unless ['|', '\\'].include?(char) cell += char end else cell += char end end # Last cell (content after the last |) is skipped end |
#start_with?(prefix) ⇒ Boolean
11 12 13 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 11 def start_with?(prefix) @trimmed_line_text.start_with?(prefix) end |
#start_with_title_keyword?(keyword) ⇒ Boolean
15 16 17 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 15 def start_with_title_keyword?(keyword) start_with?(keyword+':') # The C# impl is more complicated. Find out why. end |
#table_cells ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 36 def table_cells cells = [] self.split_table_cells(@trimmed_line_text) do |item, column| # Keeps new lines txt_trimmed_left = item.sub(/\A[ \t\v\f\r\u0085\u00A0]*/, '') txt_trimmed = txt_trimmed_left.sub(/[ \t\v\f\r\u0085\u00A0]*\z/, '') cell_indent = item.length - txt_trimmed_left.length span = Span.new(@indent + column + cell_indent, txt_trimmed) cells.push(span) end cells end |
#tags ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/gherkin_line.rb', line 84 def uncommented_line = @trimmed_line_text.split(/\s#/,2)[0] column = @indent + 1 items = uncommented_line.split('@') = [] items.each { |untrimmed| item = untrimmed.strip if item.length == 0 next end unless item =~ /^\S+$/ location = { line: @line_number, column: column } raise ParserException.new('A tag may not contain whitespace', location) end << Span.new(column, '@' + item) column += untrimmed.length + 1 } end |