Skip to content

Commit

Permalink
Improve add_inat_summmary_data
Browse files Browse the repository at this point in the history
- extracts method
- uses `HEREDOC` for readability
- fixes `InatImportsController#add_inat_summmary_data` ABC size, but trades that for violation in extracted method
  • Loading branch information
JoeCohen committed Aug 3, 2024
1 parent b6ad02c commit e37639e
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions app/controllers/observations/inat_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,31 +320,39 @@ def naming_user(identification)
end

def add_inat_summmary_data(inat_obs)
data =
"#{:USER.t}: #{inat_obs.inat_user_login}\n".
concat("#{:OBSERVED.t}: #{inat_obs.when}\n").
concat("#{:LAT_LON.t}: #{inat_obs.inat_location} " \
"+/-#{inat_obs.inat_public_positional_accuracy} m\n").
concat("#{:PLACE.t}: #{inat_obs.inat_place_guess}\n").
concat("#{:ID.t}: #{inat_obs.inat_taxon_name}\n").
concat("#{:DQA.t}: #{inat_obs.dqa}\n").
concat("#{:ANNOTATIONS.t}: #{:UNDER_DEVELOPMENT.t}\n").
concat("#{:PROJECTS.t}: #{inat_obs.inat_project_names}\n").
concat("#{:SEQUENCES.t}: #{:UNDER_DEVELOPMENT.t}\n").
concat("#{:OBSERVATION_FIELDS.t}: \n" \
"#{obs_fields(inat_obs.inat_obs_fields)}\n").
concat("#{:TAGS.t}: #{inat_obs.inat_tags.join(" ")}\n")

params = {
target: @observation,
summary: "#{:inat_data_comment.t} #{@observation.created_at}",
comment: data,
comment: comment(inat_obs),
user: inat_manager
}

Comment.create(params)
end

def comment(inat_obs)
<<~COMMENT.gsub(/^\s+/, "")
#{:USER.t}: #{inat_obs.inat_user_login}
#{:OBSERVED.t}: #{inat_obs.when}\n
#{:LAT_LON.t}: #{lat_lon_accuracy(inat_obs)}\n
#{:PLACE.t}: #{inat_obs.inat_place_guess}\n
#{:ID.t}: #{inat_obs.inat_taxon_name}\n
#{:DQA.t}: #{inat_obs.dqa}\n
#{:ANNOTATIONS.t}: #{:UNDER_DEVELOPMENT.t}\n
#{:PROJECTS.t}: #{inat_obs.inat_project_names}\n
#{:SEQUENCES.t}: #{:UNDER_DEVELOPMENT.t}\n
#{:OBSERVATION_FIELDS.t}: \n\
#{obs_fields(inat_obs.inat_obs_fields)}\n
#{:TAGS.t}: #{inat_obs.inat_tags.join(" ")}\n
COMMENT
end

def lat_lon_accuracy(inat_obs)
"#{inat_obs.inat_location} " \
"+/-#{inat_obs.inat_public_positional_accuracy} m"
end

def add_inat_sequences(inat_obs)
inat_obs.sequences.each do |sequence|
params = {
Expand Down

0 comments on commit e37639e

Please sign in to comment.