Class: WikipediaWrapper::Configuration
- Inherits:
-
Object
- Object
- WikipediaWrapper::Configuration
- Defined in:
- lib/wikipedia_wrapper/configuration.rb
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#default_ttl ⇒ Object
Returns the value of attribute default_ttl.
-
#img_height ⇒ Object
Returns the value of attribute img_height.
-
#img_width ⇒ Object
Returns the value of attribute img_width.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #image_allowed?(filename) ⇒ Boolean
- #image_restrictions ⇒ Object
- #image_restrictions=(path) ⇒ Object
-
#initialize ⇒ Configuration
constructor
Initialize the configuration with some sensible defaults.
-
#reset ⇒ Object
Reset the configuration to the initial state with the default parameters.
Constructor Details
#initialize ⇒ Configuration
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_url ⇒ Object (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_ttl ⇒ Object
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_height ⇒ Object
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_width ⇒ Object
Returns the value of attribute img_width.
6 7 8 |
# File 'lib/wikipedia_wrapper/configuration.rb', line 6 def img_width @img_width end |
#lang ⇒ Object
Returns the value of attribute lang.
6 7 8 |
# File 'lib/wikipedia_wrapper/configuration.rb', line 6 def lang @lang end |
#user_agent ⇒ Object
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
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_restrictions ⇒ Object
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.(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 |
#reset ⇒ Object
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 |