Skip to content

Commit

Permalink
Add missing properties to NtpServer
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 19, 2020
1 parent 2fb3659 commit a76b203
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/lib/y2network/ntp_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class NtpServer
attr_reader :country
# @return [String,nil] Server's location
attr_reader :location
# @return [String,nil] Location details
attr_reader :exact_location
# @return [String,nil] Stratum level
attr_reader :stratum
# @return [String,nil] Synchronization mechanism
attr_reader :synchronization
# @return [String,nil] Access policy
attr_reader :access_policy

class << self
DEFAULT_SERVERS = 4
Expand Down Expand Up @@ -70,21 +78,39 @@ def load_from_file(path)

# Constructor
#
# @param hostname [String] Server's hostname
# @param country [String] Country code (e.g., "DE")
# @param location [String] Server's location
def initialize(hostname, country: nil, location: nil)
# @param hostname [String] Hostname
# @param country [String] Country code (e.g., "DE")
# @param location [String] Location
# @param exact_location [String] Location details
# @param stratum [String] Stratum level
# @param synchronization [String] Synchronization mechanism
# @param access_policy [String] Access policy
# rubocop:disable Metrics/ParameterLists
def initialize(hostname, country: nil, location: nil, exact_location: nil, stratum: nil,
synchronization: nil, access_policy: nil)
@hostname = hostname
@country = country
@location = location
@exact_location = exact_location
@stratum = stratum
@synchronization = synchronization
@access_policy = access_policy
end
# rubocop:enable Metrics/ParameterLists

EQUALITY_METHS = [
:hostname, :country, :location, :exact_location, :stratum, :synchronization, :access_policy
].freeze
private_constant :EQUALITY_METHS

# Determines when two servers are the same
#
# @param other [NtpServer] Object to compare with
# @return [Boolean] true if both objects contain the same information; false otherwise
def ==(other)
hostname == other.hostname && country == other.country && location == other.location
EQUALITY_METHS.all? do |attr|
public_send(attr) == other.public_send(attr)
end
end

alias_method :eql?, :==
Expand Down

0 comments on commit a76b203

Please sign in to comment.