Class: Mobi::Metadata
- Inherits:
-
Object
- Object
- Mobi::Metadata
- Extended by:
- Forwardable
- Defined in:
- lib/mobi/metadata.rb
Defined Under Namespace
Classes: InvalidMobi
Constant Summary collapse
- EXTH_RECORDS =
%w(author publisher imprint description isbn subject published_at review contributor rights subject_code type source asin version)
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Raw data stream.
-
#exth_header ⇒ Object
readonly
Individual header classes for your reading pleasure.
-
#mobi_header ⇒ Object
readonly
Individual header classes for your reading pleasure.
-
#palm_doc_header ⇒ Object
readonly
Individual header classes for your reading pleasure.
Instance Method Summary collapse
-
#bookmobi? ⇒ Boolean
Determines if the file is a valid mobi file.
-
#initialize(file) ⇒ Metadata
constructor
A new instance of Metadata.
-
#title ⇒ Object
Gets the title of the book.
Constructor Details
#initialize(file) ⇒ Metadata
Returns a new instance of Metadata.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mobi/metadata.rb', line 16 def initialize(file) @file = file @data = StreamSlicer.new(file) raise InvalidMobi, "The supplied file is not in a valid mobi format" unless bookmobi? @record_zero_stream = MetadataStreams.record_zero_stream(file) @palm_doc_header = Header::PalmDocHeader.new @record_zero_stream @mobi_header = Header::MobiHeader.new @record_zero_stream @exth_stream = MetadataStreams.exth_stream(file, @mobi_header.header_length) @exth_header = Header::ExthHeader.new @exth_stream end |
Instance Attribute Details
#data ⇒ Object (readonly)
Raw data stream
12 13 14 |
# File 'lib/mobi/metadata.rb', line 12 def data @data end |
#exth_header ⇒ Object (readonly)
Individual header classes for your reading pleasure.
14 15 16 |
# File 'lib/mobi/metadata.rb', line 14 def exth_header @exth_header end |
#mobi_header ⇒ Object (readonly)
Individual header classes for your reading pleasure.
14 15 16 |
# File 'lib/mobi/metadata.rb', line 14 def mobi_header @mobi_header end |
#palm_doc_header ⇒ Object (readonly)
Individual header classes for your reading pleasure.
14 15 16 |
# File 'lib/mobi/metadata.rb', line 14 def palm_doc_header @palm_doc_header end |
Instance Method Details
#bookmobi? ⇒ Boolean
Determines if the file is a valid mobi file.
Returns true if the file is a valid MOBI.
45 46 47 |
# File 'lib/mobi/metadata.rb', line 45 def bookmobi? @data[60, 8] == "BOOKMOBI" end |
#title ⇒ Object
Gets the title of the book.
Returns a String.
33 34 35 36 37 38 39 40 |
# File 'lib/mobi/metadata.rb', line 33 def title return @title if @title offset = @mobi_header.full_name_offset length = @mobi_header.full_name_length @title = @record_zero_stream[offset, length] end |