# coding: utf-8 require 'set' require 'tag' class Page # Page is an abstract class. # # Implementors must implement several methods: # # def url => URI # def title => String # def author => Person # def content => html | nil # def rights => html | nil # # def _tags => String | Enumerable # # def _published => DateTime | nil # def _updated => DateTime | nil # def _years => Enumerable def tags # => Enumerable if @tags.nil? raw = _tags if raw.is_a?(String) raw = raw.split end @tags = raw.map{|tag|Tag.new(tag)} end @tags end def published # => DateTime | nil if @published.nil? unless _published.nil? @published = _published else unless _updated.nil? @published = _updated end end # sanity check unless _published.nil? or _updated.nil? if _updated < _published @published = _updated end end end @published end def updated # => DateTime | nil if @updated.nil? unless _updated.nil? @updated = _updated else unless _published.nil? @updated = _published end end end @updated end def years # => Enumerable if @years.nil? if published.nil? || updated.nil? @years = Set[] else first = published.year last = updated.year years = _years years.add(first) years.add(last) @years = Set[*years.select{|i|i >= first && i <= last}] end end @years end end