Class: Jeny::CodeBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/jeny/code_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, path, line, asset) ⇒ CodeBlock

Returns a new instance of CodeBlock.



4
5
6
7
8
9
# File 'lib/jeny/code_block.rb', line 4

def initialize(source, path, line, asset)
  @source = source
  @path = path
  @line = line
  @asset = asset
end

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



10
11
12
# File 'lib/jeny/code_block.rb', line 10

def asset
  @asset
end

#lineObject (readonly)

Returns the value of attribute line.



10
11
12
# File 'lib/jeny/code_block.rb', line 10

def line
  @line
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/jeny/code_block.rb', line 10

def path
  @path
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/jeny/code_block.rb', line 10

def source
  @source
end

Instance Method Details

#instantiate(data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jeny/code_block.rb', line 16

def instantiate(data)
  case d = data[asset]
  when NilClass
  when Hash
    Dialect.render(source, d) rescue source
  when Array
    d.map{|item| instantiate(asset => item) }.join("\n")  
  else
    raise Error, "Unexpected block asset: `#{asset} = #{d}`"
  end
end

#line_indexObject



12
13
14
# File 'lib/jeny/code_block.rb', line 12

def line_index
  line - 1
end