Class: Decode::Source

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, language = nil) ⇒ Source

Returns a new instance of Source.



31
32
33
34
# File 'lib/decode/source.rb', line 31

def initialize(path, language = nil)
  @path = path
  @language = language || Language.detect(path)
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



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

def language
  @language
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.for?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/decode/source.rb', line 25

def self.for?(path)
  if language = Language.detect(path)
    self.new(path, language)
  end
end

Instance Method Details

#definitions(&block) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/decode/source.rb', line 44

def definitions(&block)
  return to_enum(:definitions) unless block_given?
  
  self.open do |file|
    @language.definitions_for(file, &block)
  end
end

#open(&block) ⇒ Object



40
41
42
# File 'lib/decode/source.rb', line 40

def open(&block)
  File.open(@path, &block)
end

#segments(&block) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/decode/source.rb', line 52

def segments(&block)
  return to_enum(:segments) unless block_given?
  
  self.open do |file|
    @language.segments_for(file, &block)
  end
end