Class: EpubForge::Builder::Assets::Page

Inherits:
Asset
  • Object
show all
Defined in:
lib/epubforge/builder/assets/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_extensionObject (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_filenameObject (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

#htmlObject (readonly)

Returns the value of attribute html.



5
6
7
# File 'lib/epubforge/builder/assets/page.rb', line 5

def html
  @html
end

#media_typeObject (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_fileObject (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

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/epubforge/builder/assets/page.rb', line 5

def project
  @project
end

#section_idObject (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_formatObject (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

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

Returns:

  • (Boolean)


63
64
65
# File 'lib/epubforge/builder/assets/page.rb', line 63

def cover?
  @section_id == "cover"
end

#get_htmlObject



35
36
37
# File 'lib/epubforge/builder/assets/page.rb', line 35

def get_html
  @html = Utils::HtmlTranslator.translate( @original_file )
end

#get_titleObject



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_idObject



55
56
57
# File 'lib/epubforge/builder/assets/page.rb', line 55

def item_id
  cover? ? "cover" : self.link.basename
end


51
52
53
# File 'lib/epubforge/builder/assets/page.rb', line 51

def link
  TEXT_DIR.join( "#{@section_id}.#{@dest_extension}" )
end