Class: Alexandria::BookProviders::Preferences

Inherits:
Array
  • Object
show all
Defined in:
lib/alexandria/book_providers.rb

Defined Under Namespace

Classes: Variable

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ Preferences

Returns a new instance of Preferences.



133
134
135
# File 'lib/alexandria/book_providers.rb', line 133

def initialize(provider)
  @provider = provider
end

Instance Method Details

#[](obj) ⇒ Object



175
176
177
178
179
180
181
182
183
# File 'lib/alexandria/book_providers.rb', line 175

def [](obj)
  case obj
  when String
    var = variable_named(obj)
    var&.value
  when Integer
    super
  end
end

#addObject



171
172
173
# File 'lib/alexandria/book_providers.rb', line 171

def add(*)
  self << Variable.new(@provider, *)
end

#readObject



189
190
191
192
193
194
195
# File 'lib/alexandria/book_providers.rb', line 189

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



185
186
187
# File 'lib/alexandria/book_providers.rb', line 185

def variable_named(name)
  find { |var| var.name == name }
end