Class: Mobi::Header::MobiHeader
- Inherits:
-
Object
- Object
- Mobi::Header::MobiHeader
- Defined in:
- lib/mobi/header/mobi_header.rb
Instance Method Summary collapse
-
#exth_flag ⇒ Object
The EXTH flag.
-
#exth_header? ⇒ Boolean
Does the book have an EXTH header?.
-
#file_version ⇒ Object
The version of the MOBIpocket format used in this file.
-
#first_image_index_record_number ⇒ Object
The first record number (starting with 0) that contains an image.
-
#first_non_book_index ⇒ Object
The first record number (starting with 0) that is not the book’s text.
-
#full_name_length ⇒ Object
Length in bytes of the full name of the book.
-
#full_name_offset ⇒ Object
Offset in record 0 (not from start of file) of the full name of the book.
-
#header_length ⇒ Object
The length of the MOBI header.
-
#identifier ⇒ Object
A MOBI identifier.
-
#initialize(data) ⇒ MobiHeader
constructor
Initialize the MobiHeader.
-
#minimum_supported_mobipocket_version ⇒ Object
The minimum MOBIpocket version support needed to read this file.
-
#mobi_type ⇒ Object
The kind of Mobipocket file.
-
#raw_locale_code ⇒ Object
The raw book locale code.
-
#raw_mobi_type ⇒ Object
The kind of Mobipocket file as returned from byte code.
-
#raw_text_encoding ⇒ Object
The text encoding as return from byte code.
-
#text_encoding ⇒ Object
The text encoding.
-
#unique_id ⇒ Object
The unique ID.
Constructor Details
#initialize(data) ⇒ MobiHeader
Initialize the MobiHeader.
data - A StreamSlicer which starts at record 0 of the PalmDOC.
Returns self.
12 13 14 |
# File 'lib/mobi/header/mobi_header.rb', line 12 def initialize(data) @data = data end |
Instance Method Details
#exth_flag ⇒ Object
The EXTH flag.
If bit 6 is set, then there is an EXTH record.
Returns a Fixnum, 1 or 0.
140 141 142 |
# File 'lib/mobi/header/mobi_header.rb', line 140 def exth_flag @exth_flag ||= @data[128, 4].unpack('@3B8').first[1].to_i end |
#exth_header? ⇒ Boolean
Does the book have an EXTH header?
Returns true if the book has an EXTH header.
147 148 149 |
# File 'lib/mobi/header/mobi_header.rb', line 147 def exth_header? exth_flag == 1 end |
#file_version ⇒ Object
The version of the MOBIpocket format used in this file.
Returns a String
84 85 86 |
# File 'lib/mobi/header/mobi_header.rb', line 84 def file_version @file_version ||= @data[36, 4].unpack('N*')[0] end |
#first_image_index_record_number ⇒ Object
The first record number (starting with 0) that contains an image. Image records should be sequential.
Returns an Integer.
131 132 133 |
# File 'lib/mobi/header/mobi_header.rb', line 131 def first_image_index_record_number @first_image_index_record_number ||= @data[108, 4].unpack('N*')[0] end |
#first_non_book_index ⇒ Object
The first record number (starting with 0) that is not the book’s text.
Returns an Integer.
91 92 93 |
# File 'lib/mobi/header/mobi_header.rb', line 91 def first_non_book_index @first_non_book_index ||= @data[80, 4].unpack('N*')[0] end |
#full_name_length ⇒ Object
Length in bytes of the full name of the book.
Returns an Integer.
105 106 107 |
# File 'lib/mobi/header/mobi_header.rb', line 105 def full_name_length @full_name_length ||= @data[88, 4].unpack('N*')[0] end |
#full_name_offset ⇒ Object
Offset in record 0 (not from start of file) of the full name of the book.
Returns an Integer.
98 99 100 |
# File 'lib/mobi/header/mobi_header.rb', line 98 def full_name_offset @full_name_offset ||= @data[84, 4].unpack('N*')[0] end |
#header_length ⇒ Object
The length of the MOBI header.
Returns a Fixnum.
26 27 28 |
# File 'lib/mobi/header/mobi_header.rb', line 26 def header_length @header_length ||= @data[20, 4].unpack('N*')[0] end |
#identifier ⇒ Object
A MOBI identifier.
Returns a String.
19 20 21 |
# File 'lib/mobi/header/mobi_header.rb', line 19 def identifier @identifier ||= @data[16, 4] end |
#minimum_supported_mobipocket_version ⇒ Object
The minimum MOBIpocket version support needed to read this file.
Returns an Integer.
123 124 125 |
# File 'lib/mobi/header/mobi_header.rb', line 123 def minimum_supported_mobipocket_version @minimum_supported_mobipocket_version ||= @data[104, 4].unpack('N*')[0] end |
#mobi_type ⇒ Object
The kind of Mobipocket file.
Returns a String.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mobi/header/mobi_header.rb', line 40 def mobi_type { 2 => 'MOBIpocket Book', 3 => 'PalmDoc Book', 4 => 'Audio', 232 => 'MOBIpocket', 248 => 'KF8', 257 => 'News', 258 => 'News Feed', 259 => 'News_Magazine', 513 => 'PICS', 514 => 'WORD', 515 => 'XLS', 516 => 'PPT', 517 => 'TEXT', 518 => 'HTML' }.fetch(raw_mobi_type) end |
#raw_locale_code ⇒ Object
The raw book locale code. I believe this refers to a LCID code.
The low byte is the main language: 09 = English. The next byte is dialect: 08 = British, 04 = US. Thus US English is 1033, UK English is 2057.
Returns an Integer.
116 117 118 |
# File 'lib/mobi/header/mobi_header.rb', line 116 def raw_locale_code @raw_locale_code ||= @data[92, 4].unpack('N*')[0] end |
#raw_mobi_type ⇒ Object
The kind of Mobipocket file as returned from byte code.
Returns a Fixnum.
33 34 35 |
# File 'lib/mobi/header/mobi_header.rb', line 33 def raw_mobi_type @raw_mobi_type ||= @data[24, 4].unpack('N*')[0] end |
#raw_text_encoding ⇒ Object
The text encoding as return from byte code.
Returns a Fixnum.
61 62 63 |
# File 'lib/mobi/header/mobi_header.rb', line 61 def raw_text_encoding @text_encoding ||= @data[28, 4].unpack('N*')[0] end |
#text_encoding ⇒ Object
The text encoding.
Returns a String.
68 69 70 71 72 |
# File 'lib/mobi/header/mobi_header.rb', line 68 def text_encoding { 1252 => 'CP1252 (WinLatin1)', 65001 => 'UTF-8' }.fetch(raw_text_encoding) end |
#unique_id ⇒ Object
The unique ID.
Returns an Integer.
77 78 79 |
# File 'lib/mobi/header/mobi_header.rb', line 77 def unique_id @unique_id ||= @data[32, 4].unpack('N*')[0] end |