Class: Murdoc::Annotator
- Inherits:
-
Object
- Object
- Murdoc::Annotator
- Defined in:
- lib/murdoc/annotator.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
Source language.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#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
- #extract_metadata! ⇒ Object
-
#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]`)
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/murdoc/annotator.rb', line 15 def initialize(source, source_type, do_not_count_comment_lines = false) self.source = source self.source_type = source_type self.language = Languages.get(source_type) self.paragraphs = if !language.annotation_only? Scanner.new(language).call(self.source, do_not_count_comment_lines) else [Paragraph.new('', self.source, 0, nil)] end end |
Instance Attribute Details
#language ⇒ Object
Source language
11 12 13 |
# File 'lib/murdoc/annotator.rb', line 11 def language @language end |
#metadata ⇒ Object
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/murdoc/annotator.rb', line 6 def @metadata end |
#paragraphs ⇒ Object
Attribute accessor containing the resulting paragraphs
8 9 10 |
# File 'lib/murdoc/annotator.rb', line 8 def paragraphs @paragraphs end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/murdoc/annotator.rb', line 5 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.
30 31 32 33 34 |
# File 'lib/murdoc/annotator.rb', line 30 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
#extract_metadata! ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/murdoc/annotator.rb', line 36 def if paragraphs.count > 0 && paragraphs[0].annotation =~ /\A\s*---\n(.*?)\n\s*---\n?(.*)\z/m paragraphs[0].annotation = $2 self. = Murdoc.try_load_yaml($1) else self. = {} end end |
#source_type ⇒ Object
45 46 47 |
# File 'lib/murdoc/annotator.rb', line 45 def source_type @source_type end |
#source_type=(source_type) ⇒ Object
49 50 51 |
# File 'lib/murdoc/annotator.rb', line 49 def source_type=(source_type) @source_type = (source_type || :base).to_sym end |