Class: WikipediaWrapper::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize the configuration with some sensible defaults



10
11
12
# File 'lib/wikipedia_wrapper/configuration.rb', line 10

def initialize
  set_defaults
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



7
8
9
# File 'lib/wikipedia_wrapper/configuration.rb', line 7

def api_url
  @api_url
end

#default_ttlObject

Returns the value of attribute default_ttl.



6
7
8
# File 'lib/wikipedia_wrapper/configuration.rb', line 6

def default_ttl
  @default_ttl
end

#img_heightObject

Returns the value of attribute img_height.



6
7
8
# File 'lib/wikipedia_wrapper/configuration.rb', line 6

def img_height
  @img_height
end

#img_widthObject

Returns the value of attribute img_width.



6
7
8
# File 'lib/wikipedia_wrapper/configuration.rb', line 6

def img_width
  @img_width
end

#langObject

Returns the value of attribute lang.



6
7
8
# File 'lib/wikipedia_wrapper/configuration.rb', line 6

def lang
  @lang
end

#user_agentObject

Returns the value of attribute user_agent.



6
7
8
# File 'lib/wikipedia_wrapper/configuration.rb', line 6

def user_agent
  @user_agent
end

Instance Method Details

#image_allowed?(filename) ⇒ Boolean

Returns:

  • (Boolean)


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

def image_allowed?(filename)
  allowed_ending?(filename) && !blocked_filename?(filename) && !blocked_partial?(filename)
end

#image_restrictionsObject



25
26
27
28
29
30
# File 'lib/wikipedia_wrapper/configuration.rb', line 25

def image_restrictions
  if @image_restrictions.nil?
    self.image_restrictions = File.expand_path(File.dirname(__FILE__)) + '/default_image_restrictions.yaml'
  end
  @image_restrictions
end

#image_restrictions=(path) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/wikipedia_wrapper/configuration.rb', line 32

def image_restrictions=(path)
  begin
    @image_restrictions = YAML.load_file(path)
  rescue Errno::ENOENT # No such file
    raise WikipediaWrapper::ConfigurationError.new("The file #{path} does not exist")
  rescue Psych::SyntaxError => e
    raise WikipediaWrapper::ConfigurationError.new("SyntaxError in the file #{path}: #{e}")
  end
end

#resetObject

Reset the configuration to the initial state with the default parameters



15
16
17
18
# File 'lib/wikipedia_wrapper/configuration.rb', line 15

def reset
  set_defaults
  @image_restrictions = nil
end