Class: EbookLibrary::Ebook

Inherits:
Object
  • Object
show all
Defined in:
lib/ebook_library/ebook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/ebook_library/ebook.rb', line 7

def adapter
  @adapter
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/ebook_library/ebook.rb', line 7

def path
  @path
end

#raw_ebookObject (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

#authorObject



18
19
20
# File 'lib/ebook_library/ebook.rb', line 18

def author
  has_metadata? ? adapter.author : "unknown"
end

#formatObject



22
23
24
# File 'lib/ebook_library/ebook.rb', line 22

def format
  @format ||= File.extname(path).gsub(/^./, "")
end

#has_metadata?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ebook_library/ebook.rb', line 30

def has_metadata?
  !.nil?
end

#titleObject



14
15
16
# File 'lib/ebook_library/ebook.rb', line 14

def title
  has_metadata? ? adapter.title : "unknown"
end

#to_hashObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/ebook_library/ebook.rb', line 34

def valid?
  EbookFactory.supported_types.include?(format)
end