Class: Dovado::Router::Services

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/dovado/router/services.rb

Overview

Router Services.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Services

Create a new Dovado::Router::Services object.

Parameters:

  • args (Hash) (defaults to: nil)

    optional argiments

Since:

  • 1.0.0



27
28
29
30
31
32
33
34
35
36
# File 'lib/dovado/router/services.rb', line 27

def initialize(args=nil)
  @list = ThreadSafe::Cache.new
  @last_update = nil
  unless args.nil?
    args.each do |k,v|
      @list[Utilities.name_to_sym(k)] = v
    end
    touch!
  end
end

Instance Attribute Details

#home_automationString (readonly)

Get status of home automation service

Returns:

  • (String)

    a string with “enabled” or “disabled”

Since:

  • 1.0.3



22
23
24
# File 'lib/dovado/router/services.rb', line 22

def home_automation
  @home_automation
end

#smsString (readonly)

Get status of sms service

Returns:

  • (String)

    a string with “enabled” or “disabled”

Since:

  • 1.0.3



16
17
18
# File 'lib/dovado/router/services.rb', line 16

def sms
  @sms
end

Instance Method Details

#[](key) ⇒ Object

Fetch an entry from the Dovado::Router::Services object.

Parameters:

  • key (Symbol)

    The key to fetch.

Since:

  • 1.0.0



61
62
63
# File 'lib/dovado/router/services.rb', line 61

def [](key)
  @list[key]
end

#create_from_string(data_string = nil) ⇒ Services

Create a new Dovado::Router::Services object from a string with values from the router API.

Parameters:

  • data_string (String) (defaults to: nil)

    String with data from fetched from the router.

Returns:

Since:

  • 1.0.0



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dovado/router/services.rb', line 44

def create_from_string(data_string=nil)
  data_array = data_string.split("\n")
  data_array.each do |data_entry|
    entry_array = data_entry.split('=')
    if entry_array.length == 2
      key = entry_array[0].downcase
      val = entry_array[1]
      keysym = Utilities.name_to_sym(key)
      @list[keysym] = val
    end
  end
  touch!
end

#has_key?(key) ⇒ Boolean

Check if the Dovado::Router::Services object has a given key.

Parameters:

  • key (Symbol)

    the key to check for.

Returns:

  • (Boolean)

    true or false

Since:

  • 1.0.0



76
77
78
# File 'lib/dovado/router/services.rb', line 76

def has_key?(key)
  keys.member?(key)
end

#home_automation?Boolean

Boolean check if home automation is enabled

Returns:

  • (Boolean)

    true or false

Since:

  • 1.0.3



108
109
110
# File 'lib/dovado/router/services.rb', line 108

def home_automation?
  home_automation ? (home_automation == "enabled") : false
end

#keysArray<Symbol>

Fetch the list of entries in the Dovado::Router::Services object.

Returns:

  • (Array<Symbol>)

Since:

  • 1.0.0



68
69
70
# File 'lib/dovado/router/services.rb', line 68

def keys
  @list.keys
end

#sms?Boolean

Boolean check if sms service is enabled

Returns:

  • (Boolean)

    true or false

Since:

  • 1.0.3



96
97
98
# File 'lib/dovado/router/services.rb', line 96

def sms?
  sms ? (sms == "enabled") : false
end

#valid?Boolean

Checks if this Dovado::Router::Services object is still valid.

Returns:

  • (Boolean)

    true or false.

Since:

  • 1.0.0



83
84
85
86
# File 'lib/dovado/router/services.rb', line 83

def valid?
  return false if @last_update.nil?
  (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i)
end