1
0
Fork 0

Return primary form

This commit is contained in:
Alex Kotov 2023-02-18 15:43:07 +04:00
parent e0a9a2624b
commit 77e3d97a19
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 16 additions and 0 deletions

16
main.rb
View File

@ -26,6 +26,7 @@ get '/words/:id' do
word_id = Integer params[:id]
json({
primary_form: context.primary_form(word_id),
part_of_speech: context.part_of_speech_name(word_id),
examples: context.examples(word_id),
})
@ -67,6 +68,21 @@ private
public
##
# @return [String, nil]
#
def primary_form(word_id)
word_id = Integer word_id
column = @db_conn.exec_params(
'SELECT primary_form FROM words WHERE id = $1',
[word_id],
).values.first&.first
str = String(column).strip.freeze
str unless str.empty?
end
##
# @return [String, nil]
#