Skip to content

Commit

Permalink
Merge pull request #51 from ucd-cws/pr/50
Browse files Browse the repository at this point in the history
New "insert" functionality via Ryan Dalton
  • Loading branch information
nickrsan authored Oct 8, 2019
2 parents 888fe54 + 231dea7 commit 41d415e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Change list items
metadata.tags = ["tag1", "tag2"]
metadata.tags[1] = "another tag"
metadata.tags.append("new tag")
metadata.tags.insert(0, "first tag")
metadata.tags.remove("tag1")
metadata.tags.pop()
```
Expand Down
23 changes: 23 additions & 0 deletions arcpy_metadata/metadata_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def append(self, value):
"""
self.list_items.append(value)

def insert(self, index, value):
"""
Insert given item to list at specified index location. Functions similar to Python list inserts
:param index: location in list to insert
:param value: the value to insert into the list
:return:
"""
self.list_items.insert(index, value)

def remove(self, value):
"""
Remove given item from list
Expand Down Expand Up @@ -278,6 +287,20 @@ def append(self, item):
self.current_items.append(element)
self.element._children = self.current_items

def insert(self, index, item):
"""
Inserts an individual item to the section at specified index location
:param index: location in list to insert
:param item: the text that will be added to the multi-item section, wrapped in the appropriate tag
configured on parent object
:return:
"""

element = ET.Element(self.tag_name)
element.text = item
self.current_items.insert(index, element)
self.element._children = self.current_items

def pop(self):
"""
Remove the last element in element tree
Expand Down

0 comments on commit 41d415e

Please sign in to comment.