Class: OpenEHR::RM::DataStructures::ItemStructure::ItemTable

Inherits:
ItemStructure show all
Defined in:
lib/openehr/rm/data_structures/item_structure.rb

Constant Summary

Constants included from Common::Archetyped::LocaterConstants

Common::Archetyped::LocaterConstants::CONTENT_PATH_SEPARATOR, Common::Archetyped::LocaterConstants::CURRENT_TRANSACTION_ID, Common::Archetyped::LocaterConstants::FRAGMENT_SEPARATOR, Common::Archetyped::LocaterConstants::MULTIPART_ID_DELIMITER, Common::Archetyped::LocaterConstants::ORGANIZER_PATH_SEPARATOR

Instance Attribute Summary collapse

Attributes inherited from Common::Archetyped::Locatable

#archetype_details, #archetype_node_id, #feeder_audit, #links, #name, #uid

Attributes inherited from Common::Archetyped::Pathable

#parent

Instance Method Summary collapse

Methods inherited from Common::Archetyped::Locatable

#concept, #is_archetype_root?

Methods inherited from Common::Archetyped::Pathable

#item_at_path, #items_at_path, normalize_path, path_attribute, path_attributes, #path_children, #path_exists?, #path_of_item, #path_unique?, select_by_predicate

Constructor Details

#initialize(args = {}) ⇒ ItemTable

Returns a new instance of ItemTable.



81
82
83
84
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 81

def initialize(args = {})
  super(args)
  self.rows = args[:rows]
end

Instance Attribute Details

#rowsObject

Returns the value of attribute rows.



78
79
80
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 78

def rows
  @rows
end

Instance Method Details

#as_hierarchyObject



184
185
186
187
188
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 184

def as_hierarchy
  return Cluster.new(:name => @name,
                     :archetype_node_id => @archetype_node_id,
                     :items => @rows)
end

#column_countObject



94
95
96
97
98
99
100
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 94

def column_count
  if @rows.nil?
    return 0
  else
    return @rows[0].items.count
  end
end

#column_namesObject



110
111
112
113
114
115
116
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 110

def column_names
  if @rows.nil?
    return []
  else
    return @rows[0].items.collect{|i| i.name}
  end
end

#element_at_cell_ij(i, j) ⇒ Object



166
167
168
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 166

def element_at_cell_ij(i,j)
  return @rows[i-1].items[j-1]
end

#element_at_named_cell(row_key, column_key) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 170

def element_at_named_cell(row_key, column_key)
  column_index = 0
  @rows[0].items.each do |c|
    break if c.name.value == column_key
    column_index += 1
  end
  row_index = 0
  @rows.each do |row|
    break if row.name.value == row_key
    row_index += 1
  end
  return element_at_cell_ij(row_index + 1, column_index + 1)
end

#has_column_with_name?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


131
132
133
134
135
136
137
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 131

def has_column_with_name?(key)
  raise ArgumentError, 'invalid argument' if key.nil? or key.empty?
  self.column_names.each do |name|
    return true if name.value == key
  end
  return false
end

#has_row_with_key?(keys) ⇒ Boolean

Returns:

  • (Boolean)


146
147
148
149
150
151
152
153
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 146

def has_row_with_key?(keys)
  keys.each do |key|
    @rows.each do |row|
      return true if row.items[0].name.value == key
    end
  end
  return false
end

#has_row_with_name?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


123
124
125
126
127
128
129
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 123

def has_row_with_name?(key)
  raise ArgumentError, 'invalid argument' if key.nil? or key.empty?
  @rows.each do |row|
    return true if row.items[0].name.value == key
  end
  return false
end

#ith_row(i) ⇒ Object

Raises:

  • (ArgumentError)


118
119
120
121
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 118

def ith_row(i)
  raise ArgumentError, 'invalid index' if i<=0 or i>@rows.size
  return @rows[i - 1]
end

#named_row(key) ⇒ Object

Raises:

  • (ArgumentError)


139
140
141
142
143
144
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 139

def named_row(key)
  raise ArgumentError, 'invalid argument' unless has_row_with_name?(key)
  @rows.each do |row|
    return row if row.items[0].name.value == key
  end
end

#row_countObject



86
87
88
89
90
91
92
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 86

def row_count
  if @rows.nil?
    return 0
  else
    return @rows.size
  end
end

#row_namesObject



102
103
104
105
106
107
108
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 102

def row_names
  if @rows.nil?
    return []
  else
    return @rows.collect{|r| r.name}
  end
end

#row_with_key(keys) ⇒ Object



155
156
157
158
159
160
161
162
163
164
# File 'lib/openehr/rm/data_structures/item_structure.rb', line 155

def row_with_key(keys)
  unless has_row_with_key?(keys)
    raise ArgumentError, 'no row for key'
  end
  keys.each do |key|
    @rows.each do |row|
      return row if row.items[0].name.value == key
    end
  end
end