module Hotchoc
  class Post < Hotchoc::Base
    def id
      @item['id']
    end

    def title
      @item['title']
    end

    def subtitle
      @item['subtitle']
    end

    def identifier
      @item['identifier']
    end

    def status
      @item['status']
    end

    def publish_date
      Time.parse(@item['publish_date'])
    end

    def blocks
      @item['blocks'].to_a.map { |block| block_for(block) }
    end

    def topics
      @item['topics'].to_a.map { |topic| Hotchoc::Topic.new(topic) }
    end

    def created_at
      Time.parse(@item['created_at'])
    end

    def updated_at
      Time.parse(@item['updated_at'])
    end

    def inspect
      %(#<Hotchoc::Post: title="#{title}">)
    end
  end
end
