Class: ReVIEW::Book::ImageIndex

Inherits:
Index show all
Defined in:
lib/review/book/index.rb

Direct Known Subclasses

IconIndex, IndepImageIndex, NumberlessImageIndex

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Index

#[], #each, #has_key?, item_class, #item_type, #number

Constructor Details

#initialize(items, chapid, basedir, types, builder) ⇒ ImageIndex

Returns a new instance of ImageIndex.



196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/review/book/index.rb', line 196

def initialize(items, chapid, basedir, types, builder)
  super items
  items.each do |i|
    i.index = self
  end
  @chapid = chapid
  @basedir = basedir
  @types = types

  @image_finder = ReVIEW::Book::ImageFinder.new(basedir, chapid,
                                                builder, types)
end

Instance Attribute Details

#image_finderObject (readonly)

Returns the value of attribute image_finder.



194
195
196
# File 'lib/review/book/index.rb', line 194

def image_finder
  @image_finder
end

Class Method Details

.item_typeObject



190
191
192
# File 'lib/review/book/index.rb', line 190

def ImageIndex.item_type
  '(image|graph)'
end

.parse(src, *args) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/review/book/index.rb', line 150

def self.parse(src, *args)
  items = []
  seq = 1
  src.grep(%r<^//#{item_type()}>) do |line|
    # ex. ["//image", "id", "", "caption"]
    elements = line.split(/\[(.*?)\]/)
    if elements[1].present?
      items.push item_class().new(elements[1], seq, elements[3])
      seq += 1
      if elements[1] == ""
        warn "warning: no ID of #{item_type()} in #{line}"
      end
    end
  end
  new(items, *args)
end

Instance Method Details

#find_path(id) ⇒ Object



209
210
211
# File 'lib/review/book/index.rb', line 209

def find_path(id)
  @image_finder.find_path(id)
end