Class: Schmersion::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/schmersion/message.rb

Constant Summary collapse

REGEX =
/^([\w-]+)(?:\(([\w-]+)\))?(!)?:\s(.*?)(?:\(#(\d+)\))?$/.freeze
/^([\w-]+:|BREAKING CHANGE:)\s*(.*)$/.freeze
/^([\w-]+)\s+(#.*)$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_message) ⇒ Message

Returns a new instance of Message.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/schmersion/message.rb', line 19

def initialize(raw_message)
  @raw_message = clean(raw_message)

  parts = @raw_message.split("\n\n").map(&:strip)

  @header = parts.shift
  @paragraphs = parts
  @breaking_changes = []
  @footers = []

  parse_header
  parse_footers

  @body = @paragraphs.join("\n\n")
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



15
16
17
# File 'lib/schmersion/message.rb', line 15

def body
  @body
end

#breaking_changesObject (readonly)

Returns the value of attribute breaking_changes.



17
18
19
# File 'lib/schmersion/message.rb', line 17

def breaking_changes
  @breaking_changes
end

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/schmersion/message.rb', line 14

def description
  @description
end

#footersObject (readonly)

Returns the value of attribute footers.



11
12
13
# File 'lib/schmersion/message.rb', line 11

def footers
  @footers
end

#headerObject (readonly)

Returns the value of attribute header.



10
11
12
# File 'lib/schmersion/message.rb', line 10

def header
  @header
end

#pull_request_idObject (readonly)

Returns the value of attribute pull_request_id.



16
17
18
# File 'lib/schmersion/message.rb', line 16

def pull_request_id
  @pull_request_id
end

#scopeObject (readonly)

Returns the value of attribute scope.



13
14
15
# File 'lib/schmersion/message.rb', line 13

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/schmersion/message.rb', line 12

def type
  @type
end

Instance Method Details

#breaking_change?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/schmersion/message.rb', line 39

def breaking_change?
  @breaking_change == true ||
    @breaking_changes.size.positive?
end

#merge?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/schmersion/message.rb', line 44

def merge?
  @raw_message.match?(/\AMerge\s+/)
end

#valid?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/schmersion/message.rb', line 35

def valid?
  !@type.nil?
end