Class: CommitCommentTools::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/commit-comment-tools/entry.rb

Defined Under Namespace

Classes: InvalidEntryError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, entry_chunk) ⇒ Entry

Returns a new instance of Entry.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commit-comment-tools/entry.rb', line 27

def initialize(name, entry_chunk)
  @name = name
  @date = nil
  @read_ratio = nil
  @comment = nil

  if /\A(\d\d\d\d-\d+-\d+):(\d+)%:(.*)\z/m =~ entry_chunk
    @date = Date.parse($1).strftime("%Y-%m-%d")
    @read_ratio = $2.to_i
    @comment = $3
  else
    valid_format = "DATE:READ_RATIO%:COMMENT"
    error_message = "The expected format of entry like below:\n" +
                      "\"#{valid_format}\", but was \"#{entry_chunk}\"."
    raise(InvalidEntryError, error_message)
  end
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



25
26
27
# File 'lib/commit-comment-tools/entry.rb', line 25

def comment
  @comment
end

#dateObject (readonly)

Returns the value of attribute date.



25
26
27
# File 'lib/commit-comment-tools/entry.rb', line 25

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/commit-comment-tools/entry.rb', line 25

def name
  @name
end

#read_ratioObject (readonly)

Returns the value of attribute read_ratio.



25
26
27
# File 'lib/commit-comment-tools/entry.rb', line 25

def read_ratio
  @read_ratio
end