Class: Mapping

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

Instance Method Summary collapse

Constructor Details

#initializeMapping

Returns a new instance of Mapping.



2
3
4
# File 'lib/zim2epub/mapping.rb', line 2

def initialize
  @hash = Hash.new
end

Instance Method Details

#<<(url) ⇒ Object



6
7
8
# File 'lib/zim2epub/mapping.rb', line 6

def <<(url)
  @hash[url.to_s] = url.filename
end

#[](idx) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/zim2epub/mapping.rb', line 10

def [](idx)
  uidx = CGI::unescape(idx)
  if @hash.has_key?(uidx)
    @hash[uidx]
  else
    m = /^(.*)#(.*)$/.match(uidx)
    if m.nil?
      idx
    else
      "#{@hash[m.captures[0]]}##{m.captures[1]}"
    end
  end
end