Class: EpubForge::Builder::Assets::Page
- Defined in:
- lib/epubforge/builder/assets/page.rb
Instance Attribute Summary collapse
-
#dest_extension ⇒ Object
readonly
Returns the value of attribute dest_extension.
-
#dest_filename ⇒ Object
readonly
Returns the value of attribute dest_filename.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#media_type ⇒ Object
readonly
Returns the value of attribute media_type.
-
#original_file ⇒ Object
readonly
Returns the value of attribute original_file.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#section_id ⇒ Object
readonly
Returns the value of attribute section_id.
-
#source_format ⇒ Object
readonly
Returns the value of attribute source_format.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #cover? ⇒ Boolean
- #get_html ⇒ Object
- #get_title ⇒ Object
-
#initialize(file, metadata, project) ⇒ Page
constructor
A new instance of Page.
- #item_id ⇒ Object
- #link ⇒ Object
Constructor Details
#initialize(file, metadata, project) ⇒ Page
Returns a new instance of Page.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/epubforge/builder/assets/page.rb', line 15 def initialize file, , project raise "NIL" if project.nil? @original_file = file.fwf_filepath @source_format = @original_file.ext.to_sym @metadata = @project = project @dest_extension = "xhtml" @section_id = @original_file.basename_no_ext @dest_filename = "#{@section_id}.#{@dest_extension}" get_html get_title @content = "" @cover = false puts "Initialized #{file} with title [#{@title}]" end |
Instance Attribute Details
#dest_extension ⇒ Object (readonly)
Returns the value of attribute dest_extension.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def dest_extension @dest_extension end |
#dest_filename ⇒ Object (readonly)
Returns the value of attribute dest_filename.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def dest_filename @dest_filename end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def html @html end |
#media_type ⇒ Object (readonly)
Returns the value of attribute media_type.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def media_type @media_type end |
#original_file ⇒ Object (readonly)
Returns the value of attribute original_file.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def original_file @original_file end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def project @project end |
#section_id ⇒ Object (readonly)
Returns the value of attribute section_id.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def section_id @section_id end |
#source_format ⇒ Object (readonly)
Returns the value of attribute source_format.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def source_format @source_format end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/epubforge/builder/assets/page.rb', line 5 def title @title end |
Instance Method Details
#cover? ⇒ Boolean
63 64 65 |
# File 'lib/epubforge/builder/assets/page.rb', line 63 def cover? @section_id == "cover" end |
#get_html ⇒ Object
35 36 37 |
# File 'lib/epubforge/builder/assets/page.rb', line 35 def get_html @html = Utils::HtmlTranslator.translate( @original_file ) end |
#get_title ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/epubforge/builder/assets/page.rb', line 39 def get_title html_doc = Nokogiri::HTML( @html ) h1 = html_doc.xpath("//h1").first if h1.nil? @title = @original_file.basename.to_s.split(".")[0..-2].map(&:capitalize).join(" : ") else title = h1.content @title = title.gsub(/\s*\/+\s*/, "").epf_titlecap_words end end |
#item_id ⇒ Object
55 56 57 |
# File 'lib/epubforge/builder/assets/page.rb', line 55 def item_id cover? ? "cover" : self.link.basename end |
#link ⇒ Object
51 52 53 |
# File 'lib/epubforge/builder/assets/page.rb', line 51 def link TEXT_DIR.join( "#{@section_id}.#{@dest_extension}" ) end |