Class: Victor::CLI::RubySource

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/victor/cli/ruby_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, filename = nil) ⇒ RubySource

Returns a new instance of RubySource.



7
8
9
10
# File 'lib/victor/cli/ruby_source.rb', line 7

def initialize(code, filename = nil)
  @code = code
  @filename = filename
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/victor/cli/ruby_source.rb', line 5

def code
  @code
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/victor/cli/ruby_source.rb', line 5

def filename
  @filename
end

Instance Method Details

#evaluateObject



12
13
14
15
16
17
18
# File 'lib/victor/cli/ruby_source.rb', line 12

def evaluate
  if filename
    instance_eval code, filename
  else
    instance_eval code
  end
end

#template(template) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/victor/cli/ruby_source.rb', line 20

def template(template)
  if built_in_templates.include? template
    template = template.to_sym
  elsif !File.exist? template
    raise "Template not found #{template}\nAvailable templates: #{built_in_templates.join ', '}, or a file path"
  end

  svg.template = template
end