Class: Net::IP::Route
- Inherits:
-
Object
- Object
- Net::IP::Route
- Defined in:
- lib/net/ip/route.rb,
lib/net/ip/route/parser.rb,
lib/net/ip/route/collection.rb
Overview
Class for working with routing table entries.
Defined Under Namespace
Classes: Collection, Parser
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#via ⇒ Object
readonly
Returns the value of attribute via.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Route
constructor
Create a new route object.
- #to_h ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Route
Note:
This does NOT add the entry to the routing table. See Net::IP::Route::Collection#add for creating new routes in the routing table.
Create a new route object
14 15 16 17 18 |
# File 'lib/net/ip/route.rb', line 14 def initialize(params = {}) params.each do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def prefix @prefix end |
#via ⇒ Object (readonly)
Returns the value of attribute via.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def via @via end |
Instance Method Details
#to_h ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/net/ip/route.rb', line 20 def to_h h = {} h[:prefix] = @prefix if @prefix h[:via] = @via if @via h[:dev] = @dev if @dev h[:weight] = @weight if @weight h[:proto] = @proto if @proto h[:scope] = @scope if @scope h[:src] = @src if @src h[:metric] = @metric if @metric h[:error] = @error if @error h end |
#to_params ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/net/ip/route.rb', line 34 def to_params str = "" str << "via #{@via} " if @via str << "dev #{@dev} " if @dev str << "weight #{@weight}" if @weight str << " proto #{@proto} " if @proto str << " scope #{@scope} " if @scope str << " src #{@src} " if @src str << " metric #{@metric} " if @metric str << " error #{@error}" if @error str end |