lib/epub/content_document/navigation.rb in epub-parser-0.3.9 vs lib/epub/content_document/navigation.rb in epub-parser-0.4.0

- old
+ new

@@ -1,5 +1,7 @@ +require "set" + module EPUB module ContentDocument class Navigation < XHTML attr_accessor :navigations @@ -97,14 +99,35 @@ TOC = 'toc' PAGE_LIST = 'page_list' LANDMARKS = 'landmarks' end - attr_accessor :type + 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 + } + end + + # For backward compatibility + def type=(t) + @types << t + end %w[toc page_list landmarks].each do |type| define_method "#{type}?" do type == Type.const_get(type.upcase) end