lib/epub/content_document/navigation.rb in epub-parser-0.4.3 vs lib/epub/content_document/navigation.rb in epub-parser-0.4.4

- old
+ new

@@ -1,10 +1,12 @@ -require "set" +require "epub/content_document/typable" module EPUB module ContentDocument class Navigation < XHTML + include Typable + attr_accessor :navigations def initialize @navigations = [] @hidden = false @@ -70,10 +72,11 @@ end end class Item include Hidable + include Typable attr_accessor :items, :text, :content_document, :item attr_reader :href @@ -90,50 +93,41 @@ block.call self, depth items.each do |item| item.traverse depth + 1, &block end end - end - class Navigation < Item - module Type - TOC = 'toc' - PAGE_LIST = 'page_list' - LANDMARKS = 'landmarks' - end - - attr_reader :types - alias navigations items - alias navigations= items= - alias heading text - alias heading= text= - - def initialize - super - @types = Set.new - end - - def types=(ts) - @types = ts.kind_of?(Set) ? ts : Set.new(ts) - end - # For backward compatibility def type - @types.find {|t| - %w[toc page_list landmarks].include? t + types.find {|t| + Type::TYPES.include? t } end # For backward compatibility def type=(t) - @types << t + types << t end %w[toc page_list landmarks].each do |type| define_method "#{type}?" do - type == Type.const_get(type.upcase) + types.include? type end end + end + + # @todo Implement method to represent navigation structure + class Navigation < Item + module Type + TOC = 'toc' + PAGE_LIST = 'page_list' + LANDMARKS = 'landmarks' + end + + alias navigations items + alias navigations= items= + alias heading text + alias heading= text= end class ItemList < Array include Hidable