Class: Adhearsion::VoIP::Asterisk::ConfigFileGenerators::AsteriskConfigGenerator
- Inherits:
-
Object
- Object
- Adhearsion::VoIP::Asterisk::ConfigFileGenerators::AsteriskConfigGenerator
- Defined in:
- lib/adhearsion/voip/asterisk/config_generators/config_generator.rb
Direct Known Subclasses
Agents, Queues, Queues::QueueDefinition, Voicemail, Voicemail::ContextDefinition, Voicemail::EmailDefinition, Voicemail::RecordingDefinition
Constant Summary collapse
- SECTION_TITLE =
/(\[[\w_-]+\])/
Class Method Summary collapse
-
.create_sanitary_hash_from(config_file_content) ⇒ Object
Converts a config file into a Hash of contexts mapping to two dimensional array of pairs.
- .warning_message ⇒ Object
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ AsteriskConfigGenerator
constructor
A new instance of AsteriskConfigGenerator.
- #to_sanitary_hash ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ AsteriskConfigGenerator
Returns a new instance of AsteriskConfigGenerator.
31 32 33 |
# File 'lib/adhearsion/voip/asterisk/config_generators/config_generator.rb', line 31 def initialize yield self if block_given? end |
Class Method Details
.create_sanitary_hash_from(config_file_content) ⇒ Object
Converts a config file into a Hash of contexts mapping to two dimensional array of pairs
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/adhearsion/voip/asterisk/config_generators/config_generator.rb', line 12 def create_sanitary_hash_from(config_file_content) almost_sanitized = Hash[*config_file_content. grep(/^\s*[^;\s]/). # Grep lines that aren't commented out join. # 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 |
.warning_message ⇒ Object
24 25 26 27 |
# File 'lib/adhearsion/voip/asterisk/config_generators/config_generator.rb', line 24 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
#to_sanitary_hash ⇒ Object
35 36 37 |
# File 'lib/adhearsion/voip/asterisk/config_generators/config_generator.rb', line 35 def to_sanitary_hash self.class.create_sanitary_hash_from to_s end |