Class: Watnow::AnnotationLine

Inherits:
Object
  • Object
show all
Defined in:
lib/watnow/annotation/annotation_line.rb

Constant Summary collapse

@@id =
0
@@instances =
[]
@@tag_length =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts, annotation) ⇒ AnnotationLine

Returns a new instance of AnnotationLine.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/watnow/annotation/annotation_line.rb', line 25

def initialize(opts, annotation)
  @lineno = opts[:lineno]
  @tag = opts[:tag]
  @priority = opts[:priority] || 0
  @mention = opts[:mention] || ''
  @message = opts[:message]
  @annotation = annotation

  @annotation.priority = @priority if @priority > @annotation.priority

  # Auto increment instances id
  # Push instance into a class array
  @id = @@id += 1
  @@instances << self

  # Update class’ tag_length to the longest tag
  @@tag_length = @tag.length if @tag.length > @@tag_length
end

Instance Attribute Details

#annotationObject

Returns the value of attribute annotation.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def annotation
  @annotation
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def id
  @id
end

#linenoObject

Returns the value of attribute lineno.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def lineno
  @lineno
end

#mentionObject

Returns the value of attribute mention.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def mention
  @mention
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def message
  @message
end

#priorityObject

Returns the value of attribute priority.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def priority
  @priority
end

#tagObject

Returns the value of attribute tag.



8
9
10
# File 'lib/watnow/annotation/annotation_line.rb', line 8

def tag
  @tag
end

Class Method Details

.find(id) ⇒ Object

An ORM-like find method that returns an AnnotationLine instance



11
12
13
14
15
16
17
# File 'lib/watnow/annotation/annotation_line.rb', line 11

def self.find(id)
  @@instances.each do |instance|
    return instance if instance.id == id
  end

  nil
end

.tag_lengthObject

Returns longest tag length Used to format output



21
22
23
# File 'lib/watnow/annotation/annotation_line.rb', line 21

def self.tag_length
  @@tag_length
end

Instance Method Details

#meta_dataObject

Returns an array of “meta data” Namely: The AnnotationLine mention and priority



46
47
48
49
50
51
# File 'lib/watnow/annotation/annotation_line.rb', line 46

def 
  data = []
  data << "@#{@mention}" unless @mention.empty?
  data << Array.new(@priority + 1).join('!') if @priority > 0
  data
end