Class: Exercise::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/exercise/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, project_root_dir) ⇒ Template

Returns a new instance of Template.



45
46
47
48
49
50
# File 'lib/commands/exercise/command.rb', line 45

def initialize(path, project_root_dir)
  @full_path = path
  @dir = parent_directory(path)
  @path = relative_path(path, dir)
  @relative_directory = relative_path(dir, project_root_dir)
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



43
44
45
# File 'lib/commands/exercise/command.rb', line 43

def dir
  @dir
end

#full_pathObject (readonly)

Returns the value of attribute full_path.



43
44
45
# File 'lib/commands/exercise/command.rb', line 43

def full_path
  @full_path
end

#pathObject (readonly)

Returns the value of attribute path.



43
44
45
# File 'lib/commands/exercise/command.rb', line 43

def path
  @path
end

Instance Method Details

#filenameObject



56
57
58
# File 'lib/commands/exercise/command.rb', line 56

def filename
  File.basename(path)
end

#relative_path(full_path, root) ⇒ Object



60
61
62
# File 'lib/commands/exercise/command.rb', line 60

def relative_path(full_path, root)
  ".#{File.expand_path(full_path).gsub(File.expand_path(root), '')}"
end

#rendered_file_pathObject



52
53
54
# File 'lib/commands/exercise/command.rb', line 52

def rendered_file_path
  full_path.gsub(%r{.templates/.*?erb}, filename).gsub('.erb', '')
end