Class: Murdoc::Annotator
- Inherits:
-
Object
- Object
- Murdoc::Annotator
- Defined in:
- lib/murdoc/annotator.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
Source language.
-
#paragraphs ⇒ Object
Attribute accessor containing the resulting paragraphs.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
-
.from_file(filename, source_type = nil, do_not_count_comment_lines = false) ⇒ Object
You may also initialize annotator from file, it will even try to detect the source type from extension.
Instance Method Summary collapse
-
#initialize(source, source_type, do_not_count_comment_lines = false) ⇒ Annotator
constructor
‘source` string contains annotated source code `source_type` is one of supported source types (currently `[:ruby, :javascript]`).
- #source_type ⇒ Object
- #source_type=(source_type) ⇒ Object
Constructor Details
#initialize(source, source_type, do_not_count_comment_lines = false) ⇒ Annotator
‘source` string contains annotated source code `source_type` is one of supported source types (currently `[:ruby, :javascript]`)
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/murdoc/annotator.rb', line 13 def initialize(source, source_type, do_not_count_comment_lines = false) self.source_type = source_type self.language = Languages.get(source_type) self.source = source self.paragraphs = if !language.annotation_only? Scanner.new(language).call(source, do_not_count_comment_lines) else [Paragraph.new('', source, 0, nil)] end end |
Instance Attribute Details
#language ⇒ Object
Source language
9 10 11 |
# File 'lib/murdoc/annotator.rb', line 9 def language @language end |
#paragraphs ⇒ Object
Attribute accessor containing the resulting paragraphs
6 7 8 |
# File 'lib/murdoc/annotator.rb', line 6 def paragraphs @paragraphs end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/murdoc/annotator.rb', line 3 def source @source end |
Class Method Details
.from_file(filename, source_type = nil, do_not_count_comment_lines = false) ⇒ Object
You may also initialize annotator from file, it will even try to detect the source type from extension.
27 28 29 30 31 |
# File 'lib/murdoc/annotator.rb', line 27 def self.from_file(filename, source_type = nil, do_not_count_comment_lines = false) self.new(File.read(filename), source_type || Languages.detect(filename), do_not_count_comment_lines) end |
Instance Method Details
#source_type ⇒ Object
33 34 35 |
# File 'lib/murdoc/annotator.rb', line 33 def source_type @source_type end |
#source_type=(source_type) ⇒ Object
37 38 39 |
# File 'lib/murdoc/annotator.rb', line 37 def source_type=(source_type) @source_type = (source_type || :base).to_sym end |