Class: Jazzy::SourceMark

Inherits:
Object
  • Object
show all
Defined in:
lib/jazzy/source_mark.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mark_string = nil) ⇒ SourceMark

Returns a new instance of SourceMark.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jazzy/source_mark.rb', line 7

def initialize(mark_string = nil)
  return unless mark_string

  # Format: 'MARK: - NAME -' with dashes optional
  mark_string.sub!(/^MARK: /, '')

  if mark_string.empty?
    # Empty
    return
  elsif mark_string == '-'
    # Separator
    self.has_start_dash = true
    return
  end

  self.has_start_dash = mark_string.start_with?('- ')
  self.has_end_dash = mark_string.end_with?(' -')

  start_index = has_start_dash ? 2 : 0
  end_index = has_end_dash ? -3 : -1

  self.name = mark_string[start_index..end_index]
end

Instance Attribute Details

#has_end_dashObject

Returns the value of attribute has_end_dash.



5
6
7
# File 'lib/jazzy/source_mark.rb', line 5

def has_end_dash
  @has_end_dash
end

#has_start_dashObject

Returns the value of attribute has_start_dash.



4
5
6
# File 'lib/jazzy/source_mark.rb', line 4

def has_start_dash
  @has_start_dash
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/jazzy/source_mark.rb', line 3

def name
  @name
end

Class Method Details

.new_generic_requirements(requirements) ⇒ Object



31
32
33
34
35
# File 'lib/jazzy/source_mark.rb', line 31

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?

Returns:

  • (Boolean)


48
49
50
# File 'lib/jazzy/source_mark.rb', line 48

def can_merge?(other)
  other.empty? || other.name == name
end

#copy(other) ⇒ Object



41
42
43
44
45
# File 'lib/jazzy/source_mark.rb', line 41

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/jazzy/source_mark.rb', line 37

def empty?
  !name && !has_start_dash && !has_end_dash
end