Class: PdfExtract::Settings

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

Constant Summary collapse

@@defaults =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



18
19
20
21
# File 'lib/pdf.rb', line 18

def initialize
  @settings = {}
  @agents = {}
end

Class Method Details

.declare(key, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/pdf.rb', line 9

def self.declare key, opts={}
  default_hash = {
    :default => "",
    :description => "",
    :module => ""
  }.merge(opts)
  @@defaults[key] = default_hash
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
26
27
# File 'lib/pdf.rb', line 23

def [] key
  @settings[key] ||
    (@@defaults[key] && @@defaults[key][:default]) ||
    raise("Attempt to use undeclared setting \"#{key}\"")
end

#agent(key) ⇒ Object



46
47
48
# File 'lib/pdf.rb', line 46

def agent key
  @agents[key]
end

#modifiedObject



42
43
44
# File 'lib/pdf.rb', line 42

def modified
  @settings
end

#set(key, value, agent = "") ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/pdf.rb', line 29

def set key, value, agent=""
  if @@defaults[key]
    @settings[key] = value.to_f
    @agents[key] = agent
  else
    raise "Attempt to set an undefined setting \"#{key}\""
  end
end

#unmodifiedObject



38
39
40
# File 'lib/pdf.rb', line 38

def unmodified
  @@defaults.reject { |k, v| @settings[k] }
end