Class: Decode::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/decode/source.rb

Overview

Represents a source file in a specific language.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#languageObject (readonly)

The language of the source file.



37
38
39
# File 'lib/decode/source.rb', line 37

def language
  @language
end

#pathObject (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