Class: Alexandria::BookProviders::Preferences
- Inherits:
-
Array
- Object
- Array
- Alexandria::BookProviders::Preferences
- Defined in:
- lib/alexandria/book_providers.rb
Defined Under Namespace
Classes: Variable
Instance Method Summary collapse
- #[](obj) ⇒ Object
- #add(*args) ⇒ Object
-
#initialize(provider) ⇒ Preferences
constructor
A new instance of Preferences.
- #read ⇒ Object
- #variable_named(name) ⇒ Object
Constructor Details
#initialize(provider) ⇒ Preferences
Returns a new instance of Preferences.
130 131 132 |
# File 'lib/alexandria/book_providers.rb', line 130 def initialize(provider) @provider = provider end |
Instance Method Details
#[](obj) ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'lib/alexandria/book_providers.rb', line 173 def [](obj) case obj when String var = variable_named(obj) var ? var.value : nil when Integer super(obj) end end |
#add(*args) ⇒ Object
169 170 171 |
# File 'lib/alexandria/book_providers.rb', line 169 def add(*args) self << Variable.new(@provider, *args) end |
#read ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/alexandria/book_providers.rb', line 187 def read each do |var| name = @provider.variable_name(var) val = Alexandria::Preferences.instance.get_variable(name) var.value = val unless val.nil? || ((val == "") && var.mandatory?) end end |
#variable_named(name) ⇒ Object
183 184 185 |
# File 'lib/alexandria/book_providers.rb', line 183 def variable_named(name) find { |var| var.name == name } end |