Class: Adhearsion::Asterisk::ConfigGenerator
- Inherits:
-
Object
- Object
- Adhearsion::Asterisk::ConfigGenerator
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/adhearsion/asterisk/config_generator.rb,
lib/adhearsion/asterisk/config_generator/queues.rb,
lib/adhearsion/asterisk/config_generator/agents.rb,
lib/adhearsion/asterisk/config_generator/voicemail.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Agents, Queues, Voicemail
Constant Summary
- SECTION_TITLE =
/(\[[\w_-]+\])/
Class Method Summary (collapse)
-
+ (Object) create_sanitary_hash_from(config_file_content)
Converts a config file into a Hash of contexts mapping to two dimensional array of pairs.
- + (Object) warning_message
Instance Method Summary (collapse)
-
- (ConfigGenerator) initialize {|_self| ... }
constructor
A new instance of ConfigGenerator.
- - (Object) to_sanitary_hash
Constructor Details
- (ConfigGenerator) initialize {|_self| ... }
A new instance of ConfigGenerator
35 36 37 |
# File 'lib/adhearsion/asterisk/config_generator.rb', line 35 def initialize yield self if block_given? end |
Class Method Details
+ (Object) create_sanitary_hash_from(config_file_content)
Converts a config file into a Hash of contexts mapping to two dimensional array of pairs
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/adhearsion/asterisk/config_generator.rb', line 15 def create_sanitary_hash_from(config_file_content) almost_sanitized = Hash[*config_file_content. split("\n"). # Split the lines into an Array grep(/^\s*[^;\s]/). # Grep lines that aren't commented out join("\n"). # Convert them into one String again split(SECTION_TITLE). # Separate them into sections map(&:strip). # Remove all whitespace reject(&:empty?). # Get rid of indices that were only whitespace # Lastly, separate the keys/value pairs for the Hash map { |token| token =~ /^#{SECTION_TITLE}$/ ? token : token.split(/\n+/).sort } ] end |
+ (Object) warning_message
28 29 30 31 |
# File 'lib/adhearsion/asterisk/config_generator.rb', line 28 def %{;; THIS FILE WAS GENERATED BY ADHEARSION ON #{Time.now.ctime}!\n} + %{;; ANY CHANGES MADE BELOW WILL BE BLOWN AWAY WHEN THE FILE IS REGENERATED!\n\n} end |
Instance Method Details
- (Object) to_sanitary_hash
39 40 41 |
# File 'lib/adhearsion/asterisk/config_generator.rb', line 39 def to_sanitary_hash self.class.create_sanitary_hash_from to_s end |