Class: EpubForge::Project

Inherits:
Object show all
Defined in:
lib/project/project.rb

Constant Summary collapse

SETTINGS_FOLDER =
"settings"
CONFIG_FILE_NAME =
"config.rb"
PROJECT_ACTIONS_DIRECTORY =
"actions"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_dir) ⇒ Project

Returns a new instance of Project.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/project/project.rb', line 12

def initialize( target_dir )
  @target_dir = FunWith::Files::FilePath.new( target_dir ).expand
  
  load_configuration

  @notes_dir = config.notes_dir || @target_dir.join( "notes" )
  @book_dir  = config.book_dir  || @target_dir.join( "book" )

  @project_basename = default_project_basename
  @filename_for_epub_book = @target_dir.join( "#{default_project_basename}.epub" )
  @filename_for_mobi_book = @target_dir.join( "#{default_project_basename}.mobi" )
  @filename_for_epub_notes = @target_dir.join( "#{default_project_basename}.notes.epub" )
  @filename_for_mobi_notes = @target_dir.join( "#{default_project_basename}.notes.mobi" )
end

Instance Attribute Details

#actions_dirObject (readonly)

Returns the value of attribute actions_dir.



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

def actions_dir
  @actions_dir
end

#book_dirObject (readonly)

Returns the value of attribute book_dir.



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

def book_dir
  @book_dir
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#config_fileObject (readonly)

Returns the value of attribute config_file.



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

def config_file
  @config_file
end

#filename_for_epub_bookObject (readonly)

Returns the value of attribute filename_for_epub_book.



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

def filename_for_epub_book
  @filename_for_epub_book
end

#filename_for_epub_notesObject (readonly)

Returns the value of attribute filename_for_epub_notes.



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

def filename_for_epub_notes
  @filename_for_epub_notes
end

#filename_for_mobi_bookObject (readonly)

Returns the value of attribute filename_for_mobi_book.



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

def filename_for_mobi_book
  @filename_for_mobi_book
end

#filename_for_mobi_notesObject (readonly)

Returns the value of attribute filename_for_mobi_notes.



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

def filename_for_mobi_notes
  @filename_for_mobi_notes
end

#notes_dirObject (readonly)

Returns the value of attribute notes_dir.



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

def notes_dir
  @notes_dir
end

#project_basenameObject (readonly)

Returns the value of attribute project_basename.



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

def project_basename
  @project_basename
end

#target_dirObject (readonly)

Returns the value of attribute target_dir.



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

def target_dir
  @target_dir
end

Class Method Details

.is_project_dir?(dir) ⇒ Boolean

TODO: should test be more definitive?

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/project/project.rb', line 33

def self.is_project_dir?( dir )
  dir = dir && (dir.is_a?(String) || dir.is_a?(FunWith::Files::FilePath)) ? dir.fwf_filepath : nil
  return false if dir.nil?
  
  ( dir.exist? && dir.join( SETTINGS_FOLDER, CONFIG_FILE_NAME ).exist? && dir.join( "book" ).directory? ) ? dir : false
end

Instance Method Details

#actions_directoryObject



53
54
55
# File 'lib/project/project.rb', line 53

def actions_directory
  settings_folder( ACTIONS_DIRECTORY )
end

#chaptersObject



57
58
59
# File 'lib/project/project.rb', line 57

def chapters
  @book_dir.glob("chapter-????.*")
end

#default_project_basenameObject

shorthand string that ‘names’ the project, like the_vampire_of_the_leeky_hills. Variable-ish, used within filenames



28
29
30
# File 'lib/project/project.rb', line 28

def default_project_basename
  config.filename || @target_dir.basename.to_s.gsub( /\.epubforge$/ , '' )
end

#load_configurationObject



61
62
63
# File 'lib/project/project.rb', line 61

def load_configuration
  self.install_fwc_config_from_file( config_file )
end

#project_exists?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/project/project.rb', line 40

def project_exists?
  @target_dir.exist? && config_file.exist?
end

#settings_folder(*args) ⇒ Object



44
45
46
47
# File 'lib/project/project.rb', line 44

def settings_folder(*args)
  @settings_folder ||= @target_dir.join( SETTINGS_FOLDER )
  @settings_folder.join( *args )
end