Class: RouteNGNClient::URIMatcher

Inherits:
Model
  • Object
show all
Includes:
Comparable
Defined in:
lib/routengn_client/models/uri_matcher.rb

Direct Known Subclasses

UriMatcher

Constant Summary collapse

HEADER_ORDER =
%(contact from request)

Instance Attribute Summary

Attributes inherited from Model

#attributes, #request_account_id

Attributes included from Model::ClassMethods

#children, #only_children, #parents

Instance Method Summary collapse

Methods inherited from Model

#initialize, #to_hash, #to_json, #to_log

Methods included from Model::ClassMethods

#belongs_to, #from_hash, #from_json, #has_many, #has_one

Methods included from Logging

#init_logger, #logger

Constructor Details

This class inherits a constructor from RouteNGNClient::Model

Instance Method Details

#<=>(other) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/routengn_client/models/uri_matcher.rb', line 9

def <=>(other)
  if @attributes.header == other.attributes.header
    case (@attributes.weight <=> other.attributes.weight)
    when 0
      @attributes.id.to_s <=> other.attributes.id.to_s
    when 1 #self.weight is higher
      -1
    when -1 #self.weight is lower
      1
    else
      0
    end
  else
    return 0 if !HEADER_ORDER.include?(@attributes.header) && !HEADER_ORDER.include?(other.attributes.header)
    return -1 if !HEADER_ORDER.include?(@attributes.header)
    return 1 if !HEADER_ORDER.include?(other.attributes.header)
    return (HEADER_ORDER.index(@attributes.header) <=> HEADER_ORDER.index(other.attributes.header))
  end
end

#matches?(args = {}) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/routengn_client/models/uri_matcher.rb', line 33

def matches?(args = {})
  return false if !self.matches_header?(args[:header])
  return false if !@attributes.prefix.blank? && !self.matches_prefix?(args[:prefix])
  return false if !@attributes.user_params.blank? && !self.matches_user_params?(args[:user_params])
  return false if !@attributes.uri_params.blank? && !self.matches_uri_params?(args[:uri_params])
  return true
end

#matches_header?(arg) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/routengn_client/models/uri_matcher.rb', line 41

def matches_header?(arg)
  !@attributes.header.blank? && !arg.blank? && @attributes.header == arg
end

#matches_prefix?(arg) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/routengn_client/models/uri_matcher.rb', line 45

def matches_prefix?(arg)
  @attributes.prefix == arg
end

#matches_uri_params?(arg) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
# File 'lib/routengn_client/models/uri_matcher.rb', line 59

def matches_uri_params?(arg)
  if arg.is_a?(String)
    @attributes.uri_params == arg
  elsif arg.is_a?(Array)
    arg.include?(@attributes.uri_params)
  else
    false
  end
end

#matches_user_params?(arg) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
# File 'lib/routengn_client/models/uri_matcher.rb', line 49

def matches_user_params?(arg)
  if arg.is_a?(String)
    @attributes.user_params == arg
  elsif arg.is_a?(Array)
    arg.include?(@attributes.user_params)
  else
    false
  end
end

#weightObject



29
30
31
# File 'lib/routengn_client/models/uri_matcher.rb', line 29

def weight
  @weight ||= [@attributes.prefix, @attributes.user_params, @attributes.uri_params].select { |x| !x.blank? }.length
end