Class: Decode::Source
- Inherits:
-
Object
- Object
- Decode::Source
- Defined in:
- lib/decode/source.rb
Overview
Represents a source file in a specific language.
Instance Attribute Summary collapse
-
#A file-system path.(file-systempath.) ⇒ Object
readonly
The path of the source file.
-
#language ⇒ Object
readonly
The language of the source file.
-
#path ⇒ Object
readonly
The path of the source file.
Instance Method Summary collapse
- #code(index = nil, relative_to: nil) ⇒ Object
-
#definitions(&block) ⇒ Object
Open the source file and read all definitions.
-
#initialize(path, language) ⇒ Source
constructor
A new instance of Source.
-
#read ⇒ Object
Read the source file into an internal buffer/cache.
-
#segments(&block) ⇒ Object
Open the source file and read all segments.
Constructor Details
#initialize(path, language) ⇒ Source
Returns a new instance of Source.
26 27 28 29 30 |
# File 'lib/decode/source.rb', line 26 def initialize(path, language) @path = path @buffer = nil @language = language end |
Instance Attribute Details
#A file-system path.(file-systempath.) ⇒ Object (readonly)
The path of the source file.
34 |
# File 'lib/decode/source.rb', line 34 attr :path |
#language ⇒ Object (readonly)
The language of the source file.
38 39 40 |
# File 'lib/decode/source.rb', line 38 def language @language end |
#path ⇒ Object (readonly)
The path of the source file.
34 35 36 |
# File 'lib/decode/source.rb', line 34 def path @path end |
Instance Method Details
#code(index = nil, relative_to: nil) ⇒ Object
66 67 68 |
# File 'lib/decode/source.rb', line 66 def code(index = nil, relative_to: nil) @language.code_for(self.read, index, relative_to: relative_to) end |
#definitions(&block) ⇒ Object
Open the source file and read all definitions.
50 51 52 53 54 |
# File 'lib/decode/source.rb', line 50 def definitions(&block) return to_enum(:definitions) unless block_given? @language.definitions_for(self.read, &block) end |
#read ⇒ Object
Read the source file into an internal buffer/cache.
42 43 44 |
# File 'lib/decode/source.rb', line 42 def read @buffer ||= File.read(@path).freeze end |
#segments(&block) ⇒ Object
Open the source file and read all segments.
60 61 62 63 64 |
# File 'lib/decode/source.rb', line 60 def segments(&block) return to_enum(:segments) unless block_given? @language.segments_for(self.read, &block) end |