Class: WLIConfig::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/wliconfig.rb

Overview

Commandline option container

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addrObject

Returns the value of attribute addr.



83
84
85
# File 'lib/wliconfig.rb', line 83

def addr
  @addr
end

#passObject

Returns the value of attribute pass.



83
84
85
# File 'lib/wliconfig.rb', line 83

def pass
  @pass
end

#productObject

Returns the value of attribute product.



83
84
85
# File 'lib/wliconfig.rb', line 83

def product
  @product
end

#userObject

Returns the value of attribute user.



83
84
85
# File 'lib/wliconfig.rb', line 83

def user
  @user
end

#wlan_keyObject

Returns the value of attribute wlan_key.



83
84
85
# File 'lib/wliconfig.rb', line 83

def wlan_key
  @wlan_key
end

#wlan_modeObject

Returns the value of attribute wlan_mode.



83
84
85
# File 'lib/wliconfig.rb', line 83

def wlan_mode
  @wlan_mode
end

#wlan_ssidObject

Returns the value of attribute wlan_ssid.



83
84
85
# File 'lib/wliconfig.rb', line 83

def wlan_ssid
  @wlan_ssid
end

Instance Method Details

#update_from_file(fname) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/wliconfig.rb', line 85

def update_from_file(fname)
  return unless fname
  if FileTest.exist?(fname)
    $wlog.info("Configuration file #{fname} does exist.")
    open(fname){|f|
      yaml = YAML.load(f.read)
      @addr ||= yaml["addr"]
      @user ||= yaml["user"]
      @pass ||= yaml["pass"]
      @wlan_ssid ||= yaml["wlan-ssid"]
      @wlan_mode ||= yaml["wlan-mode"]
      @wlan_key ||= yaml["wlan-key"]
    }
    true
  else
    $wlog.warn("Configuration file #{fname} does not exist.")
    false
  end
end

#update_from_map(map) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/wliconfig.rb', line 105

def update_from_map(map)
  @addr = map[:addr] || @addr
  @user = map[:user] || @user
  @pass = map[:pass] || @pass
  @wlan_ssid = map[:wlan_ssid] || @wlan_ssid
  @wlan_mode = map[:wlan_mode] || @wlan_mode
  @wlan_key = map[:wlan_key] || @wlan_key
end

#valid?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/wliconfig.rb', line 114

def valid?
  [@addr, @user, @pass, @wlan_ssid, @wlan_mode, @wlan_key].count(nil) == 0
end