Skip to content

Commit

Permalink
Add a base class for common methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jvendetti committed Nov 1, 2024
1 parent 6d4169a commit 571410b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 142 deletions.
56 changes: 56 additions & 0 deletions app/lib/kgcl/renderers/issue_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

module KGCL
module Renderers
# Base class for generating GitHub issue content for ontology change requests
class IssueContent
attr_reader :params

def initialize(params)
@params = params
end

def render
tr = KGCL::TemplateRenderer.new(
title_template: title_template,
body_template: body_template,
bind_klass: self
)
tr.render
end

def concept_id
@params[:concept_id]
end

def concept_label
@params[:concept_label]
end

def curie
@params[:curie]
end

def github_id
@params[:github_id]
end

def orcid_id
@params[:orcid_id]
end

def username
@params[:username]
end

# These methods should be defined in subclasses to provide unique templates
def title_template
raise NotImplementedError, 'Subclasses must define a title_template'
end

def body_template
raise NotImplementedError, 'Subclasses must define a body_template'
end
end
end
end
45 changes: 7 additions & 38 deletions app/lib/kgcl/renderers/new_synonym_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,15 @@ module Renderers
#
# @see https://github.com/INCATools/kgcl KGCL documentation
#
class NewSynonymContent
attr_reader :params

def initialize(params)
@params = params
end

def render
tr = KGCL::TemplateRenderer.new(
title_template: 'new_synonym_title.erb',
body_template: 'new_synonym_body.erb',
bind_klass: self
)
tr.render
end

class NewSynonymContent < IssueContent
def comment
@params[:create_synonym][:comment]
end

def concept_id
@params[:concept_id]
end

def concept_label
@params[:concept_label]
end

def curie
@params[:curie]
end

def get_binding
binding
end

def github_id
@params[:github_id]
end

def orcid_id
@params[:orcid_id]
end

def qualifier
@params[:create_synonym][:qualifier]
end
Expand All @@ -64,8 +29,12 @@ def synonym_label
@params[:create_synonym][:preferred_label]
end

def username
@params[:username]
def title_template
'new_synonym_title.erb'
end

def body_template
'new_synonym_body.erb'
end
end
end
Expand Down
41 changes: 5 additions & 36 deletions app/lib/kgcl/renderers/node_obsoletion_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,21 @@ module Renderers
#
# @see https://github.com/INCATools/kgcl KGCL documentation
#
class NodeObsoletionContent
attr_reader :params

def initialize(params)
@params = params
end

def render
tr = KGCL::TemplateRenderer.new(
title_template: 'node_obsoletion_title.erb',
body_template: 'node_obsoletion_body.erb',
bind_klass: self
)
tr.render
end

class NodeObsoletionContent < IssueContent
def comment
@params[:node_obsoletion][:comment]
end

def concept_id
@params[:concept_id]
end

def concept_label
@params[:concept_label]
end

def curie
@params[:curie]
end

def get_binding
binding
end

def github_id
@params[:github_id]
end

def orcid_id
@params[:orcid_id]
def title_template
'node_obsoletion_title.erb'
end

def username
@params[:username]
def body_template
'node_obsoletion_body.erb'
end
end
end
Expand Down
41 changes: 7 additions & 34 deletions app/lib/kgcl/renderers/node_rename_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,25 @@ module Renderers
#
# @see https://github.com/INCATools/kgcl KGCL documentation
#
class NodeRenameContent
attr_reader :params

def initialize(params)
@params = params
end

def render
tr = KGCL::TemplateRenderer.new(
title_template: 'node_rename_title.erb',
body_template: 'node_rename_body.erb',
bind_klass: self
)
tr.render
end

class NodeRenameContent < IssueContent
def comment
@params[:node_rename][:comment]
end

def concept_label
@params[:concept_label]
end

def curie
@params[:curie]
end

def get_binding
binding
end

def github_id
@params[:github_id]
end

def orcid_id
@params[:orcid_id]
end

def new_concept_label
@params[:node_rename][:new_preferred_name]
end

def username
@params[:username]
def title_template
'node_rename_title.erb'
end

def body_template
'node_rename_body.erb'
end
end
end
Expand Down
41 changes: 7 additions & 34 deletions app/lib/kgcl/renderers/remove_synonym_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,25 @@ module Renderers
#
# @see https://github.com/INCATools/kgcl KGCL documentation
#
class RemoveSynonymContent
attr_reader :params

def initialize(params)
@params = params
end

def render
tr = KGCL::TemplateRenderer.new(
title_template: 'remove_synonym_title.erb',
body_template: 'remove_synonym_body.erb',
bind_klass: self
)
tr.render
end

class RemoveSynonymContent < IssueContent
def comment
@params[:remove_synonym][:comment]
end

def concept_label
@params[:concept_label]
end

def curie
@params[:curie]
end

def get_binding
binding
end

def github_id
@params[:github_id]
end

def orcid_id
@params[:orcid_id]
end

def synonym_label
@params[:remove_synonym][:synonym]
end

def username
@params[:username]
def title_template
'remove_synonym_title.erb'
end

def body_template
'remove_synonym_body.erb'
end
end
end
Expand Down

0 comments on commit 571410b

Please sign in to comment.