Skip to content

Commit

Permalink
Add itemcount to collections #17
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Oct 30, 2020
1 parent 949fc79 commit f0a1a34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/defaults/default_store.ad3
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@
["https://atomicdata.dev/properties/collection/value","https://atomicdata.dev/properties/datatype","https://atomicdata.dev/datatypes/atomicURL"]
["https://atomicdata.dev/properties/collection/value","https://atomicdata.dev/properties/shortname","value"]
["https://atomicdata.dev/properties/collection/value","https://atomicdata.dev/properties/description","The property is the third field of an atom. Similar to `object` in RDF. In this context, it is used as a filter in a collection."]
["https://atomicdata.dev/properties/members","https://atomicdata.dev/properties/isA","[\"https://atomicdata.dev/classes/Property\"]"]
["https://atomicdata.dev/properties/members","https://atomicdata.dev/properties/datatype","https://atomicdata.dev/datatypes/resourceArray"]
["https://atomicdata.dev/properties/members","https://atomicdata.dev/properties/shortname","members"]
["https://atomicdata.dev/properties/members","https://atomicdata.dev/properties/description","The members are the list of resources in a collection."]
["https://atomicdata.dev/properties/collection/members","https://atomicdata.dev/properties/isA","[\"https://atomicdata.dev/classes/Property\"]"]
["https://atomicdata.dev/properties/collection/members","https://atomicdata.dev/properties/datatype","https://atomicdata.dev/datatypes/resourceArray"]
["https://atomicdata.dev/properties/collection/members","https://atomicdata.dev/properties/shortname","members"]
["https://atomicdata.dev/properties/collection/members","https://atomicdata.dev/properties/description","The members are the list of resources in a collection."]
["https://atomicdata.dev/properties/collection/itemCount","https://atomicdata.dev/properties/isA","[\"https://atomicdata.dev/classes/Property\"]"]
["https://atomicdata.dev/properties/collection/itemCount","https://atomicdata.dev/properties/datatype","https://atomicdata.dev/datatypes/integer"]
["https://atomicdata.dev/properties/collection/itemCount","https://atomicdata.dev/properties/shortname","item-count"]
["https://atomicdata.dev/properties/collection/itemCount","https://atomicdata.dev/properties/description","The total number of items in the collection."]
# Collections
["https://atomicdata.dev/classes","https://atomicdata.dev/properties/isA","[\"https://atomicdata.dev/classes/Collection\"]"]
["https://atomicdata.dev/classes","https://atomicdata.dev/properties/collection/property","https://atomicdata.dev/properties/isA"]
Expand Down
6 changes: 4 additions & 2 deletions lib/src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Collection {
if let Some(prop) = self.value.clone() {
resource.set_propval(crate::urls::COLLECTION_VALUE.into(), prop.into())?;
}
// resource.set_propval(crate::urls::COLLECTION_ITEM_COUNT.into(), self.members.clone().into())?;
resource.set_propval(crate::urls::COLLECTION_ITEM_COUNT.into(), self.total_items.clone().into())?;
// Maybe include items directly
Ok(resource)
}
Expand Down Expand Up @@ -93,6 +93,8 @@ mod test {
let store = crate::Store::init();
store.populate().unwrap();
let collection = store.get_resource_extended("https://atomicdata.dev/classes").unwrap();
assert!(collection.get(urls::COLLECTION_PROPERTY).unwrap().to_string() == urls::IS_A)
assert!(collection.get(urls::COLLECTION_PROPERTY).unwrap().to_string() == urls::IS_A);
println!("Count is {}", collection.get(urls::COLLECTION_ITEM_COUNT).unwrap().to_string());
assert!(collection.get(urls::COLLECTION_ITEM_COUNT).unwrap().to_string() == "6");
}
}
1 change: 1 addition & 0 deletions lib/src/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub const MEMBERS: &str = "https://atomicdata.dev/properties/members";
pub const COLLECTION_PROPERTY: &str = "https://atomicdata.dev/properties/collection/property";
pub const COLLECTION_VALUE: &str = "https://atomicdata.dev/properties/collection/value";
pub const COLLECTION_ITEM_COUNT: &str = "https://atomicdata.dev/properties/collection/itemCount";
pub const COLLECTION_MEMBERS: &str = "https://atomicdata.dev/properties/collection/members";

// Datatypes
pub const STRING: &str = "https://atomicdata.dev/datatypes/string";
Expand Down

0 comments on commit f0a1a34

Please sign in to comment.