Class: OpenEHR::Path::Segment
- Inherits:
-
Object
- Object
- OpenEHR::Path::Segment
- Defined in:
- lib/openehr/path.rb
Instance Attribute Summary collapse
-
#archetype_node_id ⇒ Object
readonly
Returns the value of attribute archetype_node_id.
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(attribute, archetype_node_id: nil, name: nil) ⇒ Segment
constructor
A new instance of Segment.
- #predicate? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(attribute, archetype_node_id: nil, name: nil) ⇒ Segment
Returns a new instance of Segment.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openehr/path.rb', line 34 def initialize(attribute, archetype_node_id: nil, name: nil) unless attribute.is_a?(String) && attribute =~ ATTRIBUTE raise InvalidPathError, "invalid path attribute: #{attribute.inspect}" end if archetype_node_id && !(archetype_node_id =~ AT_CODE || archetype_node_id =~ ARCHETYPE_ID) raise InvalidPathError, "invalid node id: #{archetype_node_id.inspect}" end raise InvalidPathError, 'name predicate requires a node_id predicate' if name && archetype_node_id.nil? @attribute = attribute @archetype_node_id = archetype_node_id @name = name freeze end |
Instance Attribute Details
#archetype_node_id ⇒ Object (readonly)
Returns the value of attribute archetype_node_id.
32 33 34 |
# File 'lib/openehr/path.rb', line 32 def archetype_node_id @archetype_node_id end |
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
32 33 34 |
# File 'lib/openehr/path.rb', line 32 def attribute @attribute end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/openehr/path.rb', line 32 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
61 62 63 64 65 66 |
# File 'lib/openehr/path.rb', line 61 def ==(other) other.is_a?(Segment) && attribute == other.attribute && archetype_node_id == other.archetype_node_id && name == other.name end |
#hash ⇒ Object
69 70 71 |
# File 'lib/openehr/path.rb', line 69 def hash [attribute, archetype_node_id, name].hash end |
#predicate? ⇒ Boolean
49 50 51 |
# File 'lib/openehr/path.rb', line 49 def predicate? !@archetype_node_id.nil? end |
#to_s ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/openehr/path.rb', line 53 def to_s return @attribute unless predicate? s = "#{@attribute}[#{@archetype_node_id}" s += ", '#{@name}'" if @name s + ']' end |