Class: Dovado::Router::Info::Operator

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/dovado/router/info/operator.rb,
lib/dovado/router/info/operator/telia.rb

Overview

An ISP/operator.

Extend this class to create a new operator or use it as it is.

Examples:

Extending the Operator class

class MyOperator < Dovado::Router::Info::Operator
  def initialize
    super(name: "MyOperator", number: "s1234", commands: {data_remaining: "quota"})
  end
end

Using the Operator class as it is

my_operator = Dovado::Router::Info::Operator.new(name: "MyOperator", number: "s1234", commands: {data_remaining: "quota"})

Since:

  • 1.0.0

Direct Known Subclasses

Telia

Defined Under Namespace

Classes: Telia

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Operator

Create a new Operator object.

Examples:

Initializing with custom commands

my_commands = { data_remaining: "datamängd".encode("UTF-8") }
my_operator = Operator.new(name: "MyOperator", number: "s1234", commands: my_commands)

Parameters:

  • args (Hash) (defaults to: nil)

    optional arguments

Options Hash (args):

  • :number (String)

    The recipient number for this operator. Use the prefix s to indicate a “short” number, e.g “s4466”.

  • :name (String)

    Name of the operator.

  • :commands (Hash)

    Supported commands.

Since:

  • 1.0.0


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dovado/router/info/operator.rb', line 43

def initialize(args=nil)
  self.name = "Unknown"
  unless args.nil?
    @number = ""
    @name = "NoOperator"
    @commands = Operator.default_commands
    @number =   args[:number]   unless args[:number].nil?
    @name =     args[:name]     unless args[:name].nil?
    unless args[:commands].nil?
      missing_keys = []
      Operator.required_commands.each do |req|
        missing_keys << req unless args[:commands].has_key?(req)
      end
      raise ArgumentError.new "Missing required keys in hash: #{Utilities.array_to_sentence(missing_keys)}" unless missing_keys.empty?
      @commands = args[:commands]
    end
  end
end

Instance Attribute Details

#commandsHash

List of commands supported by the operator.

Returns:

  • (Hash)

Since:

  • 1.0.0


30
31
32
# File 'lib/dovado/router/info/operator.rb', line 30

def commands
  @commands
end

#nameString

Name of the operator.

Returns:

  • (String)

Since:

  • 1.0.0


27
28
29
# File 'lib/dovado/router/info/operator.rb', line 27

def name
  @name
end

#numberString

Number to send messages to for the operator.

Returns:

  • (String)

Since:

  • 1.0.0


24
25
26
# File 'lib/dovado/router/info/operator.rb', line 24

def number
  @number
end

Class Method Details

.default_commandsObject

Default commands for an operator.

Since:

  • 1.0.0


63
64
65
66
67
68
69
# File 'lib/dovado/router/info/operator.rb', line 63

def self.default_commands
  commands = {}
  required_commands.each do |command|
    commands[command] = ""
  end
  commands
end