Class: Tdms::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/tdms/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Path



6
7
8
9
10
# File 'lib/tdms/path.rb', line 6

def initialize(options={})
  load(options[:path]) if options[:path]
  @group   = options[:group]   if options[:group]
  @channel = options[:channel] if options[:channel]
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



4
5
6
# File 'lib/tdms/path.rb', line 4

def channel
  @channel
end

#groupObject (readonly)

Returns the value of attribute group.



4
5
6
# File 'lib/tdms/path.rb', line 4

def group
  @group
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/tdms/path.rb', line 20

def ==(other)
  if other.is_a?(String)
    self.to_s == other
  elsif other.is_a?(Path)
    self.dump == other.dump
  else
    super
  end
end

#channel?Boolean



53
54
55
# File 'lib/tdms/path.rb', line 53

def channel?
  (! @channel.nil?)
end

#dumpObject

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
# File 'lib/tdms/path.rb', line 30

def dump
  raise ArgumentError if channel && group.nil?

  parts = [""]
  parts << ("'" + group.sub("'","''")   + "'") if group
  parts << ("'" + channel.sub("'","''") + "'") if channel

  dumped = parts.join("/")
  dumped.empty? ? "/" : dumped
end

#group?Boolean



49
50
51
# File 'lib/tdms/path.rb', line 49

def group?
  (! @group.nil?) && (@channel.nil?)
end

#load(path) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/tdms/path.rb', line 12

def load(path)
  segments = path.split("/").map do |seg|
    seg.sub(/^'/,'').sub(/'$/,'').sub("''", "'")
  end

  _, @group, @channel = *segments
end

#root?Boolean



45
46
47
# File 'lib/tdms/path.rb', line 45

def root?
  (! channel?) && (! group?)
end

#to_sObject



41
42
43
# File 'lib/tdms/path.rb', line 41

def to_s
  dump
end