Class: Collins::Address
Constant Summary
Constants included from Util::Logging
Util::Logging::DEFAULT_LOG_FORMAT
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#asset_id ⇒ Object
Returns the value of attribute asset_id.
-
#gateway ⇒ Object
Returns the value of attribute gateway.
-
#id ⇒ Object
Returns the value of attribute id.
-
#netmask ⇒ Object
Returns the value of attribute netmask.
-
#pool ⇒ Object
Returns the value of attribute pool.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model = {}) ⇒ Address
constructor
A new instance of Address.
- #is_addressable? ⇒ Boolean
- #is_private? ⇒ Boolean
- #is_public? ⇒ Boolean
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Util
#deep_copy_hash, #get_asset_or_tag, included, #require_non_empty, #require_that, #stringify_hash, #symbolize_hash
Methods included from Util::Logging
Constructor Details
#initialize(model = {}) ⇒ Address
Returns a new instance of Address.
33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
6 7 8 |
# File 'lib/collins/address.rb', line 6 def address @address end |
#asset_id ⇒ Object
Returns the value of attribute asset_id.
6 7 8 |
# File 'lib/collins/address.rb', line 6 def asset_id @asset_id end |
#gateway ⇒ Object
Returns the value of attribute gateway.
6 7 8 |
# File 'lib/collins/address.rb', line 6 def gateway @gateway end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/collins/address.rb', line 6 def id @id end |
#netmask ⇒ Object
Returns the value of attribute netmask.
6 7 8 |
# File 'lib/collins/address.rb', line 6 def netmask @netmask end |
#pool ⇒ Object
Returns the value of attribute pool.
6 7 8 |
# File 'lib/collins/address.rb', line 6 def pool @pool end |
Class Method Details
.from_json(json) ⇒ Object
9 10 11 12 13 14 15 |
# 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) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Boolean
28 29 30 |
# File 'lib/collins/address.rb', line 28 def is_public? address not is_private?(address) end |
Instance Method Details
#is_addressable? ⇒ Boolean
46 47 48 |
# File 'lib/collins/address.rb', line 46 def is_addressable? @address.length > 0 end |
#is_private? ⇒ Boolean
50 51 52 |
# File 'lib/collins/address.rb', line 50 def is_private? Collins::Address.is_private? @address end |
#is_public? ⇒ Boolean
54 55 56 |
# File 'lib/collins/address.rb', line 54 def is_public? is_addressable? and not is_private? end |
#to_hash ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
68 69 70 |
# 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 |