Class: Blammo::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/blammo/commit.rb

Constant Summary collapse

COMMIT_RE =
/^(\[\w+\]) (.*)/
TAGS_RE_MAP =
{
  :added   => /(ADDED|NEW)/,
  :changed => /(CHANGED)/,
  :fixed   => /(FIXED)/,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sha, message) ⇒ Commit

Returns a new instance of Commit.



13
14
15
16
17
18
19
# File 'lib/blammo/commit.rb', line 13

def initialize(sha, message)
  @sha = sha

  if message && message.match(Commit::COMMIT_RE)
    @tag, @message = Commit.parse_tag($1), $2
  end
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/blammo/commit.rb', line 11

def message
  @message
end

#shaObject (readonly)

Returns the value of attribute sha.



11
12
13
# File 'lib/blammo/commit.rb', line 11

def sha
  @sha
end

#tagObject (readonly)

Returns the value of attribute tag.



11
12
13
# File 'lib/blammo/commit.rb', line 11

def tag
  @tag
end

Class Method Details

.parse_tag(value) ⇒ Object



35
36
37
38
# File 'lib/blammo/commit.rb', line 35

def self.parse_tag(value)
  tag, regexp = TAGS_RE_MAP.detect {|tag, regexp| value =~ regexp}
  tag
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/blammo/commit.rb', line 21

def to_s
  @message
end

#to_yaml(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/blammo/commit.rb', line 25

def to_yaml(options = {})
  message = "[#{@tag.to_s.upcase}] #{@message}"

  if @sha
    {@sha => message}
  else
    message
  end.to_yaml(options)
end