Skip to content

Commit

Permalink
Put context gsub manipulations into the Identity and Code objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
CoralineAda committed Jul 6, 2024
1 parent 8e72e20 commit cc591fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/controllers/codebooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def show
@next_section = sections[sections.index(@context.to_sym) + 1]

if params[:id].split('_').last == "given"
@frequencies = Identity.histogram(@context.gsub("_given","").gsub("klass","class").gsub("_","-"))
@frequencies = Identity.histogram(@context)
else
@frequencies = Code.histogram(@context.gsub("_exp","").gsub("klass","class").gsub("_","-"))
@frequencies = Code.histogram(@context)
end

if @context.include?("_exp") || @context.include?("_feel")
Expand Down
13 changes: 7 additions & 6 deletions app/models/code.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
class Code
include ActiveGraph::Node

property :name
property :context

before_validation :strip_whitespace
before_validation :downcase

validates :name, presence: true
validates :context, presence: true
validates_uniqueness_of :name, :scope => :context

has_many :out, :personas, rel_class: :Experiences
has_many :in, :categories, rel_class: :CategorizedAs

def self.histogram(context)
context = context.gsub("_exp","").gsub("klass","class").gsub("_","-")
where(context: context).query_as(:t).with('t, count{(t)-[:EXPERIENCES]-()} AS c').where('c > 0').order('c DESC').return('t.name, c').inject({}) {|h,t| h[t.values[0]] ||= 0; h[t.values[0]] += t.values[1]; h}
end

private

def strip_whitespace
self.name.strip!
end

def downcase
self.name.downcase!
end
end
end
17 changes: 9 additions & 8 deletions app/models/identity.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
class Identity
include ActiveGraph::Node

property :name
property :context

before_validation :strip_whitespace

validates :name, presence: true
validates :context, presence: true

has_many :out, :personas, rel_class: :IdentifiesWith

def self.histogram(context)
context = context.gsub("_given","").gsub("klass","class").gsub("_","-")
where(context: context).query_as(:i).with('i, count{(i)-[:IDENTIFIES_WITH]-(p:Persona)} AS c').return('i.name, c').order('c DESC').inject({}) {|h,i| h[i.values[0]] ||= 0; h[i.values[0]] += i.values[1]; h}
end

private

def strip_whitespace
self.name.strip!
end
end

end

0 comments on commit cc591fd

Please sign in to comment.