Class: SelectPdfApi::EnvConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/select_pdf_api/env_config.rb

Overview

Config class using the ENV variable or the API key.

Constant Summary collapse

API_OPTIONS =

API Options list

%w{
	key page_size page_orientation pdf_name margin_top margin_right margin_bottom margin_left
	page_numbers user_password owner_password web_page_width web_page_height
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env_var) ⇒ Object

Returns SelectPdfApi::EnvConfig.

Parameters:

  • env_var (String)

    Name of the environment variable the API key is set to.



17
18
19
20
# File 'lib/select_pdf_api/env_config.rb', line 17

def initialize(env_var='SELECT_PDF_KEY')
	@env_var = env_var
	configure_options
end

Instance Attribute Details

#dataObject (readonly)

API Options Hash



6
7
8
# File 'lib/select_pdf_api/env_config.rb', line 6

def data
  @data
end

Instance Method Details

#configure_optionsHash

Sets the initial values for the API options. The API key is set from the environment variable.

Returns:

  • (Hash)

    API options with API key set.



26
27
28
29
30
31
# File 'lib/select_pdf_api/env_config.rb', line 26

def configure_options
	@data = {}
	API_OPTIONS.each {|option| @data[option] = ''}
	@data['key'] = ENV[@env_var]
	@data
end

#optionsHash

Required by all config classes as the common interface for the main class.

Returns:

  • (Hash)

    Collection of options loaded from the config file.



36
37
38
# File 'lib/select_pdf_api/env_config.rb', line 36

def options
	@data.delete_if{|k, v| v.empty?}
end