Class: Threatinator::Parsers::XML::Path
- Inherits:
-
Object
- Object
- Threatinator::Parsers::XML::Path
- Defined in:
- lib/threatinator/parsers/xml/path.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#end_with?(other_path) ⇒ Boolean
length = 5 0 1 2 3 4 /a/b/c/d/e 0 1 /d/e.
- #eql?(other) ⇒ Boolean
-
#initialize(str_or_parts = nil) ⇒ Path
constructor
A new instance of Path.
- #length ⇒ Object
- #pop ⇒ Object
- #push(name) ⇒ Object
Constructor Details
#initialize(str_or_parts = nil) ⇒ Path
Returns a new instance of Path.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/threatinator/parsers/xml/path.rb', line 13 def initialize(str_or_parts = nil) @parts = case str_or_parts when ::String if str_or_parts.length == 0 or !str_or_parts.start_with?('/') raise ArgumentError.new('str_or_parts must be a String beginning with "/"') end r = str_or_parts.split('/') r.shift r when ::Array str_or_parts.dup when nil [] else raise TypeError.new("Expected argument must be a String, Array, or nil") end end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
5 6 7 |
# File 'lib/threatinator/parsers/xml/path.rb', line 5 def parts @parts end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 |
# File 'lib/threatinator/parsers/xml/path.rb', line 32 def ==(other) @parts == other.parts end |
#end_with?(other_path) ⇒ Boolean
length = 5
0 1 2 3 4
/a/b/c/d/e
0 1
/d/e
46 47 48 49 50 51 52 53 54 |
# File 'lib/threatinator/parsers/xml/path.rb', line 46 def end_with?(other_path) return false if other_path.length > self.length return true if other_path.length == 0 pos = length - other_path.length other_path.parts.each_with_index do |other_part, idx| return false unless @parts[(pos + idx)] == other_part end true end |
#eql?(other) ⇒ Boolean
36 37 38 39 |
# File 'lib/threatinator/parsers/xml/path.rb', line 36 def eql?(other) other.kind_of?(self.class) && self == other end |
#length ⇒ Object
64 65 66 |
# File 'lib/threatinator/parsers/xml/path.rb', line 64 def length @parts.length end |
#pop ⇒ Object
60 61 62 |
# File 'lib/threatinator/parsers/xml/path.rb', line 60 def pop @parts.pop end |
#push(name) ⇒ Object
56 57 58 |
# File 'lib/threatinator/parsers/xml/path.rb', line 56 def push(name) @parts.push(name) end |