Skip to content

Commit

Permalink
Adjusted the parsing of description from google document to contain e…
Browse files Browse the repository at this point in the history
…verything under the heading
  • Loading branch information
tomasdrga committed Dec 12, 2024
1 parent 8df1f5e commit 8868035
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions app/models/phase_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def load_metadata(summary)
current_label = nil
current_status_content = ''
collecting = false
description_collecting = false
description_content = ''

doc.search('h3, p, ul, li').each do |element|
if element.name == 'h3'
Expand All @@ -111,12 +113,22 @@ def load_metadata(summary)
current_status_content = ''
end

if description_collecting
assign_value(metadata_mapping["Stručný opis:"], description_content.strip)
description_collecting = false
description_content = ''
end

collecting = true if current_label == "Čo sa práve deje"
description_collecting = true if current_label == "Stručný opis"
end

if collecting && %w[p ul].include?(element.name)
current_status_content += element.to_html

elsif description_collecting && %w[p ul li].include?(element.name)
description_content += element.to_html

elsif element.name == 'p'
strong_element = element.at('strong')
if strong_element
Expand All @@ -139,6 +151,10 @@ def load_metadata(summary)
if collecting && metadata_mapping.key?("Čo sa práve deje:")
assign_value(metadata_mapping["Čo sa práve deje:"], current_status_content)
end

if description_collecting && metadata_mapping.key?("Stručný opis:")
assign_value(metadata_mapping["Stručný opis:"], description_content.strip)
end
end

def assign_value(attribute, value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeDescriptionToTextInPhaseRevisions < ActiveRecord::Migration[5.1]
def change
change_column :phase_revisions, :description, :text
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20240621112043) do
ActiveRecord::Schema.define(version: 20241212091706) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -39,7 +39,7 @@
t.string "title", null: false
t.string "full_name"
t.string "guarantor"
t.string "description"
t.text "description"
t.string "budget"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down

0 comments on commit 8868035

Please sign in to comment.