Class: PDFWalker::Walker::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfwalker/config.rb

Constant Summary collapse

DEFAULT_CONFIG_FILE =
"#{File.expand_path("~")}/.pdfwalker.conf.yml"
DEFAULT_CONFIG =
{
    "Debug" =>
    {
        "Profiling" => false,
        "ProfilingOutputDir" => "prof",
        "Verbosity" => Origami::Parser::VERBOSE_TRACE,
        "IgnoreFileHeader" => true
    },

    "UI" =>
    {
        "LastOpenedDocuments" => []
    }
}
NLOG_RECENT_FILES =
5

Instance Method Summary collapse

Constructor Details

#initialize(configfile = DEFAULT_CONFIG_FILE) ⇒ Config

Returns a new instance of Config.



47
48
49
50
51
52
53
54
55
56
# File 'lib/pdfwalker/config.rb', line 47

def initialize(configfile = DEFAULT_CONFIG_FILE)
    begin
        @conf = YAML.load(File.open(configfile))
    rescue
        @conf = DEFAULT_CONFIG
    ensure
        @filename = configfile
        set_missing_values
    end
end

Instance Method Details

#ignore_header?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/pdfwalker/config.rb', line 87

def ignore_header?
    @conf["Debug"]['IgnoreFileHeader']
end

#last_opened_file(filepath) ⇒ Object



58
59
60
61
62
63
# File 'lib/pdfwalker/config.rb', line 58

def last_opened_file(filepath)
    @conf["UI"]['LastOpenedDocuments'].push(filepath).uniq!
    @conf["UI"]['LastOpenedDocuments'].delete_at(0) while @conf["UI"]['LastOpenedDocuments'].size > NLOG_RECENT_FILES

    save
end

#profile?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/pdfwalker/config.rb', line 74

def profile?
    @conf["Debug"]['Profiling']
end

#profile_output_dirObject



78
79
80
# File 'lib/pdfwalker/config.rb', line 78

def profile_output_dir
    @conf["Debug"]['ProfilingOutputDir']
end

#recent_files(n = NLOG_RECENT_FILES) ⇒ Object



65
66
67
# File 'lib/pdfwalker/config.rb', line 65

def recent_files(n = NLOG_RECENT_FILES)
    @conf["UI"]['LastOpenedDocuments'].last(n).reverse
end

#saveObject



100
101
102
# File 'lib/pdfwalker/config.rb', line 100

def save
    File.open(@filename, "w").write(@conf.to_yaml)
end

#set_ignore_header(bool) ⇒ Object



82
83
84
85
# File 'lib/pdfwalker/config.rb', line 82

def set_ignore_header(bool)
    @conf["Debug"]['IgnoreFileHeader'] = bool
    save
end

#set_profiling(bool) ⇒ Object



69
70
71
72
# File 'lib/pdfwalker/config.rb', line 69

def set_profiling(bool)
    @conf["Debug"]['Profiling'] = bool
    save
end

#set_verbosity(level) ⇒ Object



91
92
93
94
# File 'lib/pdfwalker/config.rb', line 91

def set_verbosity(level)
    @conf["Debug"]['Verbosity'] = level
    save
end

#verbosityObject



96
97
98
# File 'lib/pdfwalker/config.rb', line 96

def verbosity
    @conf["Debug"]['Verbosity']
end