Class: ReVIEW::Book::ImageIndex

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

Direct Known Subclasses

IconIndex, IndepImageIndex, NumberlessImageIndex

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Index

#[], #each, #item_type, #key?, #number

Constructor Details

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

Returns a new instance of ImageIndex.



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/review/book/index.rb', line 176

def initialize(items, chapid, basedir, types, builder)
  super(items)
  items.each do |item|
    item.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.



174
175
176
# File 'lib/review/book/index.rb', line 174

def image_finder
  @image_finder
end

Class Method Details

.item_typeObject



170
171
172
# File 'lib/review/book/index.rb', line 170

def self.item_type
  '(image|graph|imgtable)'
end

.parse(src, *args) ⇒ Object



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

def self.parse(src, *args)
  items = []
  seq = 1
  src.grep(%r{\A//#{item_type}}) do |line|
    # ex. ["//image", "id", "", "caption"]
    elements = line.split(/\[(.*?)\]/)
    if elements[1].present?
      if line =~ %r{\A//imgtable}
        items.push(ReVIEW::Book::Index::Item.new(elements[1], 0, elements[3]))
      else ## %r<\A//(image|graph)>
        items.push(ReVIEW::Book::Index::Item.new(elements[1], seq, elements[3]))
        seq += 1
      end
      if elements[1] == ''
        ReVIEW.logger.warn "warning: no ID of #{item_type} in #{line}"
      end
    end
  end
  new(items, *args)
end

Instance Method Details

#find_path(id) ⇒ Object



188
189
190
# File 'lib/review/book/index.rb', line 188

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