Class: BigbluebuttonRails::DialNumber
- Inherits:
-
Object
- Object
- BigbluebuttonRails::DialNumber
- Defined in:
- lib/bigbluebutton_rails/dial_number.rb
Class Method Summary collapse
- .get_dial_number_from_ordinal(ordinal, pattern = nil, opt = {}) ⇒ Object
- .get_ordinal_from_dial_number(number, pattern = nil, opt = {}) ⇒ Object
- .get_symbol(opt) ⇒ Object
-
.randomize(pattern = nil, opt = {}) ⇒ Object
Generates a random dial number based on the ‘pattern` (e.g. ’123x-xxxx’).
Class Method Details
.get_dial_number_from_ordinal(ordinal, pattern = nil, opt = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bigbluebutton_rails/dial_number.rb', line 16 def self.get_dial_number_from_ordinal(ordinal, pattern=nil, opt={}) return nil if pattern.nil? sym = get_symbol(opt) number_size = pattern.count(sym) ordinal_str = ordinal.to_s.rjust(number_size,'0').reverse dial_number = pattern.reverse ordinal_str.each_char do |n| dial_number.sub!(sym, n) end dial_number.reverse end |
.get_ordinal_from_dial_number(number, pattern = nil, opt = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bigbluebutton_rails/dial_number.rb', line 31 def self.get_ordinal_from_dial_number(number, pattern=nil, opt={}) return nil if pattern.nil? sym = get_symbol(opt) regexp = Regexp.new(pattern.gsub(sym, '([0-9])')) # make a pattern to capture only the numbers match = regexp.match(number) # extract only the numbers # join the numbers and turn then into an ordinal integer ordinal = match[1, match.size].join.to_i if match.present? ordinal end |
.get_symbol(opt) ⇒ Object
44 45 46 |
# File 'lib/bigbluebutton_rails/dial_number.rb', line 44 def self.get_symbol opt opt[:symbol] || 'x' end |
.randomize(pattern = nil, opt = {}) ⇒ Object
Generates a random dial number based on the ‘pattern` (e.g. ’123x-xxxx’)
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bigbluebutton_rails/dial_number.rb', line 5 def self.randomize(pattern=nil, opt={}) return nil if pattern.nil? sym = get_symbol(opt) size = pattern.count(sym) # e.g. random from 0 to 999 if the pattern has 3 x's num = SecureRandom.random_number((10 ** size) - 1) get_dial_number_from_ordinal(num, pattern, opt) end |