Class: PathModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ebngen/adapter/_path_modifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rootdir_table) ⇒ PathModifier

Returns a new instance of PathModifier.



9
10
11
# File 'lib/ebngen/adapter/_path_modifier.rb', line 9

def initialize(rootdir_table)
    @rootdir_table = rootdir_table
end

Instance Attribute Details

#rootdir_tableObject (readonly)

Returns the value of attribute rootdir_table.



7
8
9
# File 'lib/ebngen/adapter/_path_modifier.rb', line 7

def rootdir_table
  @rootdir_table
end

Instance Method Details

#fullpath(rootdir_name, relpath) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ebngen/adapter/_path_modifier.rb', line 13

def fullpath(rootdir_name, relpath)
    Core.assert(@rootdir_table.has_key?(rootdir_name)) do
        "rootdir '#{rootdir_name}' is not present in table '@{rootdir_table}'"
    end
    if (@rootdir_table[ rootdir_name ] && !@rootdir_table[ rootdir_name ].empty?)
        relpath = File.join(
            @rootdir_table[ rootdir_name ].gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR), relpath.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
        )
    end
    return relpath.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
end

#relpath(project_full_path, root_dir_path) ⇒ Object



25
26
27
# File 'lib/ebngen/adapter/_path_modifier.rb', line 25

def relpath(project_full_path, root_dir_path)
   return Pathname.new(root_dir_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)).relative_path_from(Pathname.new(project_full_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR))).to_s
end