Class: Paneron::Register::Raw::ItemClass
- Inherits:
-
Object
- Object
- Paneron::Register::Raw::ItemClass
- Defined in:
- lib/paneron/register/raw/item_class.rb
Instance Attribute Summary collapse
-
#data_set_path ⇒ Object
readonly
Returns the value of attribute data_set_path.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#item_class_name ⇒ Object
readonly
Returns the value of attribute item_class_name.
-
#item_class_path ⇒ Object
readonly
Returns the value of attribute item_class_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data_set_path, item_class_name, extension = "yaml") ⇒ ItemClass
constructor
A new instance of ItemClass.
- #item_lutamls ⇒ Object
- #item_uuids ⇒ Object
- #items(uuid = nil) ⇒ Object
- #to_lutaml ⇒ Object
Constructor Details
#initialize(data_set_path, item_class_name, extension = "yaml") ⇒ ItemClass
Returns a new instance of ItemClass.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/paneron/register/raw/item_class.rb', line 12 def initialize( data_set_path, item_class_name, extension = "yaml" ) item_class_path = File.join(data_set_path, item_class_name) self.class.validate_item_class_path(item_class_path) @extension = extension @data_set_path = data_set_path @item_class_name = item_class_name @item_class_path = item_class_path @items_uuids = nil @items = {} end |
Instance Attribute Details
#data_set_path ⇒ Object (readonly)
Returns the value of attribute data_set_path.
9 10 11 |
# File 'lib/paneron/register/raw/item_class.rb', line 9 def data_set_path @data_set_path end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
9 10 11 |
# File 'lib/paneron/register/raw/item_class.rb', line 9 def extension @extension end |
#item_class_name ⇒ Object (readonly)
Returns the value of attribute item_class_name.
9 10 11 |
# File 'lib/paneron/register/raw/item_class.rb', line 9 def item_class_name @item_class_name end |
#item_class_path ⇒ Object (readonly)
Returns the value of attribute item_class_path.
9 10 11 |
# File 'lib/paneron/register/raw/item_class.rb', line 9 def item_class_path @item_class_path end |
Class Method Details
.validate_item_class_path(path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/paneron/register/raw/item_class.rb', line 27 def self.validate_item_class_path(path) unless File.exist?(path) raise Paneron::Register::Error, "Item class path does not exist" end unless File.directory?(path) raise Paneron::Register::Error, "Item class path is not a directory" end end |
Instance Method Details
#item_lutamls ⇒ Object
64 65 66 |
# File 'lib/paneron/register/raw/item_class.rb', line 64 def item_lutamls items.values.map(&:to_lutaml) end |
#item_uuids ⇒ Object
45 46 47 48 |
# File 'lib/paneron/register/raw/item_class.rb', line 45 def item_uuids @item_uuids ||= Dir.glob(File.join(item_class_path, "*.#{extension}")) .map { |file| File.basename(file, ".#{extension}") } end |
#items(uuid = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/paneron/register/raw/item_class.rb', line 50 def items(uuid = nil) if uuid.nil? item_uuids.reduce({}) do |acc, uuid| acc[uuid] = items(uuid) acc end else @items[uuid] ||= Paneron::Register::Raw::Item.new( item_class_path, uuid ) end end |