Class: EbookLibrary::Ebook
- Inherits:
-
Object
- Object
- EbookLibrary::Ebook
- Defined in:
- lib/ebook_library/ebook.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#raw_ebook ⇒ Object
readonly
Returns the value of attribute raw_ebook.
Instance Method Summary collapse
- #author ⇒ Object
- #format ⇒ Object
- #has_metadata? ⇒ Boolean
-
#initialize(ebook_path) ⇒ Ebook
constructor
A new instance of Ebook.
- #title ⇒ Object
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(ebook_path) ⇒ Ebook
Returns a new instance of Ebook.
8 9 10 11 12 |
# File 'lib/ebook_library/ebook.rb', line 8 def initialize(ebook_path) @path = ebook_path @raw_ebook = File.open ebook_path @adapter = get_adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/ebook_library/ebook.rb', line 7 def adapter @adapter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/ebook_library/ebook.rb', line 7 def path @path end |
#raw_ebook ⇒ Object (readonly)
Returns the value of attribute raw_ebook.
7 8 9 |
# File 'lib/ebook_library/ebook.rb', line 7 def raw_ebook @raw_ebook end |
Instance Method Details
#author ⇒ Object
18 19 20 |
# File 'lib/ebook_library/ebook.rb', line 18 def ? adapter. : "unknown" end |
#format ⇒ Object
22 23 24 |
# File 'lib/ebook_library/ebook.rb', line 22 def format @format ||= File.extname(path).gsub(/^./, "") end |
#has_metadata? ⇒ Boolean
30 31 32 |
# File 'lib/ebook_library/ebook.rb', line 30 def !.nil? end |
#title ⇒ Object
14 15 16 |
# File 'lib/ebook_library/ebook.rb', line 14 def title ? adapter.title : "unknown" end |
#to_hash ⇒ Object
26 27 28 |
# File 'lib/ebook_library/ebook.rb', line 26 def to_hash Hash[attrs.map{|attr| [attr, send(attr)]}] if valid? end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/ebook_library/ebook.rb', line 34 def valid? EbookFactory.supported_types.include?(format) end |