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
174 175 176 177 178 179 180 181 182 |
# File 'lib/alexandria/book_providers.rb', line 174 def [](obj) case obj when String var = variable_named(obj) var ? var.value : nil when Integer super(obj) end end |
#add(*args) ⇒ Object
170 171 172 |
# File 'lib/alexandria/book_providers.rb', line 170 def add(*args) self << Variable.new(@provider, *args) end |
#read ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/alexandria/book_providers.rb', line 188 def read each do |var| = @provider.variable_name(var) val = Alexandria::Preferences.instance.send() var.value = val unless val.nil? || ((val == '') && var.mandatory?) end end |
#variable_named(name) ⇒ Object
184 185 186 |
# File 'lib/alexandria/book_providers.rb', line 184 def variable_named(name) find { |var| var.name == name } end |