Class: Jazzy::SourceMark
- Inherits:
-
Object
- Object
- Jazzy::SourceMark
- Defined in:
- lib/jazzy/source_mark.rb
Instance Attribute Summary collapse
-
#has_end_dash ⇒ Object
Returns the value of attribute has_end_dash.
-
#has_start_dash ⇒ Object
Returns the value of attribute has_start_dash.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#can_merge?(other) ⇒ Boolean
Can we merge the contents of another mark into our own?.
- #copy(other) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(mark_string = nil) ⇒ SourceMark
constructor
A new instance of SourceMark.
Constructor Details
#initialize(mark_string = nil) ⇒ SourceMark
Returns a new instance of SourceMark.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jazzy/source_mark.rb', line 9 def initialize(mark_string = nil) return unless mark_string # Format: 'MARK: - NAME -' with dashes optional mark_content = mark_string.sub(/^MARK: /, '') if mark_content.empty? # Empty return elsif mark_content == '-' # Separator self.has_start_dash = true return end self.has_start_dash = mark_content.start_with?('- ') self.has_end_dash = mark_content.end_with?(' -') start_index = has_start_dash ? 2 : 0 end_index = has_end_dash ? -3 : -1 self.name = mark_content[start_index..end_index] end |
Instance Attribute Details
#has_end_dash ⇒ Object
Returns the value of attribute has_end_dash.
7 8 9 |
# File 'lib/jazzy/source_mark.rb', line 7 def has_end_dash @has_end_dash end |
#has_start_dash ⇒ Object
Returns the value of attribute has_start_dash.
6 7 8 |
# File 'lib/jazzy/source_mark.rb', line 6 def has_start_dash @has_start_dash end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/jazzy/source_mark.rb', line 5 def name @name end |
Class Method Details
.new_generic_requirements(requirements) ⇒ Object
33 34 35 36 37 |
# File 'lib/jazzy/source_mark.rb', line 33 def self.new_generic_requirements(requirements) marked_up = requirements.gsub(/\b([^=:]\S*)\b/, '`\1`') text = "Available where #{marked_up}" new(text) end |
Instance Method Details
#can_merge?(other) ⇒ Boolean
Can we merge the contents of another mark into our own?
50 51 52 |
# File 'lib/jazzy/source_mark.rb', line 50 def can_merge?(other) other.empty? || other.name == name end |
#copy(other) ⇒ Object
43 44 45 46 47 |
# File 'lib/jazzy/source_mark.rb', line 43 def copy(other) self.name = other.name self.has_start_dash = other.has_start_dash self.has_end_dash = other.has_end_dash end |
#empty? ⇒ Boolean
39 40 41 |
# File 'lib/jazzy/source_mark.rb', line 39 def empty? !name && !has_start_dash && !has_end_dash end |