Class: OpenEHR::Path::Segment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, archetype_node_id: nil, name: nil) ⇒ Segment

Returns a new instance of Segment.

Raises:



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_idObject (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

#attributeObject (readonly)

Returns the value of attribute attribute.



32
33
34
# File 'lib/openehr/path.rb', line 32

def attribute
  @attribute
end

#nameObject (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

#hashObject



69
70
71
# File 'lib/openehr/path.rb', line 69

def hash
  [attribute, archetype_node_id, name].hash
end

#predicate?Boolean

Returns:

  • (Boolean)


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

def predicate?
  !@archetype_node_id.nil?
end

#to_sObject



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