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
-
#definitions(&block) ⇒ Object
Open the source file and read all definitions.
-
#initialize(path, language) ⇒ Source
constructor
A new instance of Source.
-
#open(&block) ⇒ Object
Open the source file for reading.
-
#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 |
# File 'lib/decode/source.rb', line 26 def initialize(path, language) @path = path @language = language end |
Instance Attribute Details
#A file-system path.(file-systempath.) ⇒ Object (readonly)
The path of the source file.
33 |
# File 'lib/decode/source.rb', line 33 attr :path |
#language ⇒ Object (readonly)
The language of the source file.
37 38 39 |
# File 'lib/decode/source.rb', line 37 def language @language end |
#path ⇒ Object (readonly)
The path of the source file.
33 34 35 |
# File 'lib/decode/source.rb', line 33 def path @path end |
Instance Method Details
#definitions(&block) ⇒ Object
Open the source file and read all definitions.
50 51 52 53 54 55 56 |
# File 'lib/decode/source.rb', line 50 def definitions(&block) return to_enum(:definitions) unless block_given? self.open do |file| @language.definitions_for(file, &block) end end |
#open(&block) ⇒ Object
Open the source file for reading.
42 43 44 |
# File 'lib/decode/source.rb', line 42 def open(&block) File.open(@path, &block) end |
#segments(&block) ⇒ Object
Open the source file and read all segments.
62 63 64 65 66 67 68 |
# File 'lib/decode/source.rb', line 62 def segments(&block) return to_enum(:segments) unless block_given? self.open do |file| @language.segments_for(file, &block) end end |