Class: Tdms::Path
- Inherits:
-
Object
- Object
- Tdms::Path
- Defined in:
- lib/tdms/path.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #channel? ⇒ Boolean
- #dump ⇒ Object
- #group? ⇒ Boolean
-
#initialize(options = {}) ⇒ Path
constructor
A new instance of Path.
- #load(path) ⇒ Object
- #root? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Path
6 7 8 9 10 |
# File 'lib/tdms/path.rb', line 6 def initialize(={}) load([:path]) if [:path] @group = [:group] if [:group] @channel = [:channel] if [:channel] end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
4 5 6 |
# File 'lib/tdms/path.rb', line 4 def channel @channel end |
#group ⇒ Object (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 |
#dump ⇒ Object
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_s ⇒ Object
41 42 43 |
# File 'lib/tdms/path.rb', line 41 def to_s dump end |