Skip to content

Commit

Permalink
chore: unused code reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar committed Dec 23, 2024
1 parent 624a059 commit 11b30cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/glossarist/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ class Asset < Lutaml::Model::Serializable
def eql?(asset)
path == asset.path
end

def hash
path.hash
end
end
end
6 changes: 6 additions & 0 deletions lib/glossarist/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module Glossarist
class Collection
include Enumerable

# Path to concepts directory.
# @return [String]
attr_accessor :path

# @param path [String]
# concepts directory path, either absolute or relative to CWD
def initialize(path: nil)
@path = path
@index = {}
Expand Down
4 changes: 0 additions & 4 deletions lib/glossarist/designation/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class Expression < Base
map :grammar_info, to: :grammar_info
end

def grammar_info
@grammar_info.empty? ? nil : @grammar_info
end

def self.of_yaml(hash, options = {})
gender = hash.delete("gender") || hash.delete(:gender)
number = hash.delete("plurality") || hash.delete(:plurality)
Expand Down
32 changes: 24 additions & 8 deletions lib/glossarist/managed_concept_collection.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module Glossarist
class ManagedConceptCollection < Lutaml::Model::Serializable
class ManagedConceptCollection
include Enumerable

attribute :managed_concepts_ids, :hash, default: -> { {} }
attribute :managed_concepts, ManagedConcept, collection: true
attribute :concept_manager, ConceptManager, default: -> { ConceptManager.new }
attr_accessor :managed_concepts

yaml do
map :managed_concepts_ids, to: :managed_concepts_ids
map :managed_concepts, to: :managed_concepts
map :concept_manager, to: :concept_manager
def initialize
@managed_concepts = []
@managed_concepts_ids = {}
@concept_manager = ConceptManager.new
end

def to_h
Expand All @@ -22,15 +20,33 @@ def each(&block)
@managed_concepts.each(&block)
end

# Returns concept with given ID, if it is present in collection, or +nil+
# otherwise.
#
# @param id [String]
# ManagedConcept ID
# @return [ManagedConcept, nil]
def fetch(id)
@managed_concepts.find { |c| c.uuid == id || c.uuid == @managed_concepts_ids[id] }
end
alias :[] :fetch

# If ManagedConcept with given ID is present in this collection, then
# returns it. Otherwise, instantiates a new ManagedConcept, adds it to
# the collection, and returns it.
#
# @param id [String]
# ManagedConcept ID
# @return [ManagedConcept]
def fetch_or_initialize(id)
fetch(id) or store(Config.class_for(:managed_concept).of_yaml(data: { id: id }))
end

# Adds concept to the collection. If collection contains a concept with
# the same ID already, that concept is replaced.
#
# @param managed_concept [ManagedConcept]
# ManagedConcept about to be added
def store(managed_concept)
@managed_concepts ||= []
@managed_concepts << managed_concept
Expand Down

0 comments on commit 11b30cc

Please sign in to comment.