Class: RubyTDMS::Path
- Inherits:
-
Object
- Object
- RubyTDMS::Path
- Defined in:
- lib/ruby_tdms/path.rb
Constant Summary collapse
- PATH_MATCHER =
/(?:(?<!\\))\//
- RAW_MATCHER =
/(?:^|(?<='))\/(?:(?=')|$)/
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #dump ⇒ Object
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Path
constructor
Can initialize with parts, path, or raw.
- #inspect ⇒ Object
- #load(string) ⇒ Object
- #path ⇒ Object
- #path=(value) ⇒ Object
- #raw ⇒ Object
- #raw=(value) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Path
Can initialize with parts, path, or raw. Elements can contain / only in raw or parts forms.
7 8 9 10 11 12 |
# File 'lib/ruby_tdms/path.rb', line 7 def initialize( = {}) raise ArgumentError, 'Initialize with at most one of +parts+, +path+, or +raw+.' if .length > 1 @parts = [:parts] || [] self.path = [:path] if .has_key? :path self.raw = [:raw] if .has_key? :raw end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_tdms/path.rb', line 65 def ==(other) if other.is_a? String self.to_s == other elsif other.is_a? self.class self.dump == other.dump else super end end |
#dump ⇒ Object
15 16 17 |
# File 'lib/ruby_tdms/path.rb', line 15 def dump to_s end |
#hash ⇒ Object
20 21 22 |
# File 'lib/ruby_tdms/path.rb', line 20 def hash to_s.hash end |
#inspect ⇒ Object
25 26 27 |
# File 'lib/ruby_tdms/path.rb', line 25 def inspect "#<#{self.class.name}:#{self.object_id} path=#{path.inspect}>" end |
#load(string) ⇒ Object
30 31 32 |
# File 'lib/ruby_tdms/path.rb', line 30 def load(string) self.path = string end |
#path ⇒ Object
35 36 37 |
# File 'lib/ruby_tdms/path.rb', line 35 def path '/' + @parts.map { |part| part.gsub('/', '\/') }.join('/') end |
#path=(value) ⇒ Object
40 41 42 |
# File 'lib/ruby_tdms/path.rb', line 40 def path=(value) @parts = value._?('').split(PATH_MATCHER).reject { |x| x.length == 0 }.map { |part| decode_part part } end |
#raw ⇒ Object
45 46 47 |
# File 'lib/ruby_tdms/path.rb', line 45 def raw '/' + @parts.map { |part| encode_part part }.join('/') end |
#raw=(value) ⇒ Object
50 51 52 |
# File 'lib/ruby_tdms/path.rb', line 50 def raw=(value) @parts = value._?('').split(RAW_MATCHER).reject { |x| x.length == 0 }.map { |part| decode_raw_part part } end |
#to_a ⇒ Object
55 56 57 |
# File 'lib/ruby_tdms/path.rb', line 55 def to_a @parts end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/ruby_tdms/path.rb', line 60 def to_s path end |