Class: Zim::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/zim/url.rb

Overview

url entry class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f) ⇒ Url

read url from file



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zim/url.rb', line 17

def initialize(f)
  @f = f
  mime_type = f.read_int16

  if mime_type == 0xffff
    # redirect
    @mime_type      = nil
    param_len       = f.read_int8
    @namespace      = f.read_int8.chr
    @revision       = f.read_int32
    @redirect_index = f.read_int32
    @cluster_number = nil
    @blob_number    = nil
    @url            = f.read_cstr
    @title          = f.read_cstr
    @params         = f.read_str(param_len)
  else
    @mime_type      = f.mime_types[mime_type]
    param_len       = f.read_int8
    @namespace      = f.read_int8.chr
    @revision       = f.read_int32
    @redirect_index = nil
    @cluster_number = f.read_int32
    @blob_number    = f.read_int32
    @url            = f.read_cstr
    @title          = f.read_cstr
    @params         = f.read_str(param_len)
  end
end

Instance Attribute Details

#blob_numberObject (readonly)

Returns the value of attribute blob_number.



11
12
13
# File 'lib/zim/url.rb', line 11

def blob_number
  @blob_number
end

#cluster_numberObject (readonly)

Returns the value of attribute cluster_number.



10
11
12
# File 'lib/zim/url.rb', line 10

def cluster_number
  @cluster_number
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



6
7
8
# File 'lib/zim/url.rb', line 6

def mime_type
  @mime_type
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/zim/url.rb', line 7

def namespace
  @namespace
end

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/zim/url.rb', line 14

def params
  @params
end

#redirect_indexObject (readonly)

Returns the value of attribute redirect_index.



9
10
11
# File 'lib/zim/url.rb', line 9

def redirect_index
  @redirect_index
end

#revisionObject (readonly)

Returns the value of attribute revision.



8
9
10
# File 'lib/zim/url.rb', line 8

def revision
  @revision
end

#titleObject (readonly)

Returns the value of attribute title.



13
14
15
# File 'lib/zim/url.rb', line 13

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/zim/url.rb', line 12

def url
  @url
end

Instance Method Details

#blobObject

receive the blob of this url



53
54
55
56
57
58
59
60
# File 'lib/zim/url.rb', line 53

def blob
  url = self
  if redirect?
    url = @f.urls[@redirect_index]
  end

  @f.clusters[@cluster_number].read_blob(@blob_number)
end

#redirect?Boolean

checks if this url is a redirect

Returns:

  • (Boolean)


48
49
50
# File 'lib/zim/url.rb', line 48

def redirect?
  @mime_type.nil?
end

#to_sObject



62
63
64
# File 'lib/zim/url.rb', line 62

def to_s
  "/#{@namespace}/#{@url}"
end