Class: PdfExtract::Settings
- Inherits:
-
Object
- Object
- PdfExtract::Settings
- Defined in:
- lib/pdf.rb
Constant Summary collapse
- @@defaults =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #agent(key) ⇒ Object
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
- #modified ⇒ Object
- #set(key, value, agent = "") ⇒ Object
- #unmodified ⇒ Object
Constructor Details
#initialize ⇒ Settings
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 |
#modified ⇒ Object
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 |
#unmodified ⇒ Object
38 39 40 |
# File 'lib/pdf.rb', line 38 def unmodified @@defaults.reject { |k, v| @settings[k] } end |