Class: Peregrin::Blueprint
- Defined in:
- lib/peregrin/blueprint.rb
Overview
Some ebook formats contain ‘metadata’ files that describe the contents of the ebook package. Since Peregrin use ‘metadata’ to refer to key-value pairs of information about the book, we call these files ‘blueprints’.
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#rel ⇒ Object
Returns the value of attribute rel.
Attributes inherited from Resource
#attributes, #media_type, #src
Instance Method Summary collapse
- #document ⇒ Object
-
#initialize(rel, src, contents, media_type = 'application/xml', atts = {}) ⇒ Blueprint
constructor
A new instance of Blueprint.
- #marshal_dump ⇒ Object
- #marshal_load(h) ⇒ Object
- #xml? ⇒ Boolean
Constructor Details
#initialize(rel, src, contents, media_type = 'application/xml', atts = {}) ⇒ Blueprint
Returns a new instance of Blueprint.
9 10 11 12 13 |
# File 'lib/peregrin/blueprint.rb', line 9 def initialize(rel, src, contents, media_type = 'application/xml', atts = {}) @rel = rel @contents = contents super(src, media_type, atts) end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
7 8 9 |
# File 'lib/peregrin/blueprint.rb', line 7 def contents @contents end |
#rel ⇒ Object
Returns the value of attribute rel.
7 8 9 |
# File 'lib/peregrin/blueprint.rb', line 7 def rel @rel end |
Instance Method Details
#document ⇒ Object
16 17 18 19 |
# File 'lib/peregrin/blueprint.rb', line 16 def document raise "Not an XML document: #{src}" unless xml? @document ||= Nokogiri::XML::Document.parse(contents) end |
#marshal_dump ⇒ Object
27 28 29 30 31 |
# File 'lib/peregrin/blueprint.rb', line 27 def marshal_dump instance_variables.inject({}) { |acc, v| v.to_s == '@document' ? acc : acc.update(v => instance_variable_get(v)) } end |
#marshal_load(h) ⇒ Object
34 35 36 |
# File 'lib/peregrin/blueprint.rb', line 34 def marshal_load(h) h.each_pair { |k, v| instance_variable_set(k, v) } end |
#xml? ⇒ Boolean
22 23 24 |
# File 'lib/peregrin/blueprint.rb', line 22 def xml? media_type.match(/xml$/) ? true : false end |