class Collins::Address
Attributes
address[RW]
asset_id[RW]
gateway[RW]
id[RW]
netmask[RW]
pool[RW]
Public Class Methods
from_json(json)
click to toggle source
# File lib/collins/address.rb, line 9 def from_json json return [] if json.nil? || json.empty? if not json.is_a?(Array) then json = [json] end json.map { |j| Collins::Address.new j } end
is_private?(address)
click to toggle source
# File lib/collins/address.rb, line 17 def is_private? address if address =~ /^10\./ then true elsif address =~ /^192\.168\./ then true elsif address =~ /^172\.(?:1[6-9]|2[0-9]|3[0-1])\./ then true else false end end
is_public?(address)
click to toggle source
# File lib/collins/address.rb, line 28 def is_public? address not is_private?(address) end
new(model = {})
click to toggle source
# File lib/collins/address.rb, line 33 def initialize model = {} hash = symbolize_hash(model).inject({}) do |result, (k,v)| result[k.downcase] = v result end @id = hash[:id].to_s.to_i @asset_id = hash[:asset_id].to_s.to_i @address = hash[:address].to_s @gateway = hash[:gateway].to_s @netmask = hash[:netmask].to_s @pool = hash[:pool].to_s end
Public Instance Methods
is_addressable?()
click to toggle source
# File lib/collins/address.rb, line 46 def is_addressable? @address.length > 0 end
is_private?()
click to toggle source
# File lib/collins/address.rb, line 50 def is_private? Collins::Address.is_private? @address end
is_public?()
click to toggle source
# File lib/collins/address.rb, line 54 def is_public? is_addressable? and not is_private? end
to_hash()
click to toggle source
# File lib/collins/address.rb, line 58 def to_hash { :address => @address, :gateway => @gateway, :netmask => @netmask, :pool => @pool, :is_private => is_private?, :is_public => is_public? } end
to_s()
click to toggle source
# File lib/collins/address.rb, line 68 def to_s "Collins::Address(address = %{address}, gateway = %{gateway}, netmask = %{netmask}, is_private = %{is_private})" % to_hash end