Class: EASYFPM::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/easyfpm/mapping.rb

Constant Summary collapse

@@regexpStruct =

Waited format:

#A comment src-dir => newdir src-file => newdir/new-file

New path can’t start with /

{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappingfile) ⇒ Mapping

Returns a new instance of Mapping.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/easyfpm/mapping.rb', line 30

def initialize(mappingfile)
  file = File.open(mappingfile, 'r')
  @hashmap={}
  while !file.eof?
    line = file.readline
    #We ignore the empty lines
    next if @@regexpStruct[:emptyline].match(line)
    #We ignore the comment lines
    next if @@regexpStruct[:commentline].match(line)
    linematch = @@regexpStruct[:mappingline].match(line)
    if linematch
      #We are on a mapping line
      #Verifying that new path don't start with /
      raise EASYFPM::InvalidConfiguration, "New path can't start with / mapping file #{mappingfile}:\n\t#{line}" if linematch[2][0] == "/"
      @hashmap[linematch[1]]=linematch[2]
    else
      raise EASYFPM::InvalidConfiguration, "The following line is not recognized in mapping file #{mappingfile}:\n\t#{line}"
    end
  end
end

Instance Attribute Details

#hashmapObject (readonly)

Returns the value of attribute hashmap.



28
29
30
# File 'lib/easyfpm/mapping.rb', line 28

def hashmap
  @hashmap
end