-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push formatting output through formatter class
- Loading branch information
1 parent
f0535e5
commit c7a85ed
Showing
4 changed files
with
78 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module Gemtastic | ||
class AnnotationFormatter | ||
private | ||
attr_reader :annotation, :annotations | ||
|
||
public | ||
def initialize annotation, annotations=nil | ||
@annotation = annotation | ||
@annotations = annotations || { | ||
'homepage_uri' => 'Homepage', | ||
'source_code_uri' => 'Source', | ||
'documentation_uri' => 'Documentation' | ||
} | ||
end | ||
|
||
def to_s | ||
to_s_lines.map { |line| "#{indent}#{line}" }.join("\n") | ||
end | ||
|
||
private | ||
|
||
def to_s_lines | ||
[ | ||
header, | ||
name, | ||
underline, | ||
spacer, | ||
description, | ||
spacer, | ||
annotate, | ||
spacer, | ||
header, | ||
spacer | ||
].flatten | ||
end | ||
|
||
def spacer | ||
"#~#" | ||
end | ||
|
||
def header | ||
"#~" * 40 | ||
end | ||
|
||
def description | ||
"#{spacer} #{annotation.get['info'].gsub(/\n/, "\n#{indent}#{spacer} ")}" | ||
end | ||
|
||
def name | ||
"#{spacer} #{annotation.get['name']}" | ||
end | ||
|
||
def underline | ||
"#{spacer} " + ('-' * annotation.get['name'].length) | ||
end | ||
|
||
def annotate | ||
@annotations.each_pair.map { |uri, header| | ||
"#{spacer} #{'%-14s' % (header<<':')} #{annotation.get[uri]}" | ||
} | ||
end | ||
def indent | ||
@annotation.indent | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Gemtastic | ||
class ColorizedAnnotationFormatter < AnnotationFormatter | ||
end | ||
end |