Class: Bookit::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/bookit/article.rb

Constant Summary collapse

REQUIRED_ATTRS =
[:author, :date_published, :url, :title, :content]

Instance Method Summary collapse

Constructor Details

#initialize(attrs, parser = Bookit::Parser::Html) ⇒ Article

Returns a new instance of Article.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bookit/article.rb', line 9

def initialize(attrs, parser=Bookit::Parser::Html)
  @attributes = attrs.dup

  REQUIRED_ATTRS.each do |key|
    raise "Required attribute #{key} not found." unless @attributes[key]
    self.send "#{key}=", @attributes[key]
  end

  # parse raw content into array of generic content
  @content = Content.new(@content, parser)
end

Instance Method Details

#to_print(emitter = Bookit::Emitter::Pdf) ⇒ Object

Article’s to print method outputs the given input content into the given emitter document type. We output PDF by default.



23
24
25
# File 'lib/bookit/article.rb', line 23

def to_print(emitter=Bookit::Emitter::Pdf)
  emitter.new(self).generate
end