Return statement takes long (no computation) - ruby-on-rails

I have encountered a confusing problem
I have fetching some records, and recursively selected their self associated records. This is fairly quick, but when I return the data, even after all the computations/filtering has been done, the return statement hangs for like a second before returning the result
# recursively looks for succesful carrier product price on owner carrier products
#
def referenced_carrier_product_price
start = Time.now
puts "start"
ancestors = CarrierProduct.find_carrier_product_ancestors(carrier_product_id: self.id).includes(:carrier_product_price).references(:carrier_product_price)
puts "ancestors #{Time.now - start}"
parent = ancestors.select{ |cp| cp.id == self.carrier_product_id }.first
puts "parent #{Time.now - start}"
until parent.nil? || ancestors.empty?
puts "check #{Time.now - start}"
is_successful = parent.carrier_product_price.try('successful?')
puts "is_successful #{Time.now - start}"
price = parent.carrier_product_price
puts "price #{Time.now - start}"
return price if is_successful
puts "CCP #{Time.now - start}"
parent = ancestors.select{ |cp| cp.id == parent.carrier_product_id }.first
puts "Loop parent #{Time.now - start}"
end
return
end
Below I show the output to console
parent 0.003545
check 0.003572
is_successful 0.003609
price 0.003621
... 1 second later
=> #<CarrierProductPrice....
As you can see, all the computation is completed at 0.003621, yet i still get the result a second later
PS. this record stores a fairly large serialised field which may be the cause?
Any advice?

It appears you are doing this in IRB. IRB has to call .inspect on the result to print it out, and in this case it is probably taking a while to do the inspect on a large field, and it takes a while to write it to the console.

Related

inserting numbers into an array and checking

I wanted to insert numbers into this array, so that the user could choose how many to put until he wanted to leave.
The first problem - when the user puts in option 2 to exit, it still
asks for the number once more before it exits, and also inserts it
into the array.
I tried to create a check so that if the user puts in a number
already added previously, it won't be possible, but it's not working
either.
numbers = []
option = 1
loop do
if option == 1
puts 'To enter a number type 1 - To exit type 2'
option = gets.chomp.to_i
print 'Type: '
number_user = gets.chomp.to_i
if number_user == numbers
puts 'This number has already been entered!'
elsif
numbers << number_user
end
elsif option == 2
puts "Bye!"
puts "Entered numbers - #{numbers}"
return
else
puts "Invalid option"
return
end
end
Use break to break out of the loop. And Array#include? to test if the number has already been input:
numbers = []
loop do
option = gets.chomp.to_i
if option == 1
puts 'To enter a number type 1 - To exit type 2'
option = gets.chomp.to_i
print 'Type: '
number_user = gets.chomp.to_i
if number_user == numbers
puts 'This number has already been entered!'
elsif
numbers << number_user
end
elsif option == 2
break
else
puts "Invalid option"
end
end
However unless you really hate your users or are building a numpad interface you can just let them exit by leaving the input blank or by inputting an exit character ("q" or "Q") instead of having to enter 1 over and over:
numbers = []
loop do
puts 'Please enter a number (or leave blank to exit):'
input = gets.chomp
if ["", "Q"].include?(input.upcase)
break
elsif numbers.to_i.include?(input.to_i)
puts 'This number has already been entered!'
else
numbers << input.to_i
end
end
puts "Bye!"
puts "Entered numbers - #{numbers}"

How to get my API to return more than one value in Ruby

My CLI project is working almost correctly, however, is only returning one value. I would like my program to return multiple values.
Here's the code:
def display_info
puts "You'll love the following spots!"
puts "********************************"
#objects.each.with_index(1) {|brewery, index| puts "#{index}. #{brewery.name}"}
puts "Please make a selection by index number for more information:"
puts "****************************************************"
puts "Type Quit to end. Type Menu to try another location."
input = gets.strip.downcase
if(input.to_i > 0)
#brewery = #objects[input.to_i - 1]
puts "name: #{#brewery.name}"
puts "street: #{#brewery.street}"
puts "city: #{#brewery.city}"
puts "phone: #{#brewery.phone}"
puts "website_url: #{#brewery.website_url}"
display_info
elsif (input == "quit")
quit
elsif (input == "menu")
start
else
puts "Ooops, please try again to get more info:"
display_info
end
end
Here's the input result if that helps.
Austin
You'll love the following spots!
********************************
1. Oasis Texas Brewing Company
Please make a selection by index number for more information:
****************************************************
Type Quit to end. Type Menu to try another location.
quit
Goodbye. Drink responsibly and enjoy.
What can I do to return more than one value?
Here's the source of this code. This is the content.
class Breweries::API
def self.get_breweries(input)
#breweries_hash = HTTParty.get("https://api.openbrewerydb.org/breweries?by_city=#{input}")
return if #breweries_hash.empty? #empty array handle
breweries_obj = {
name: #breweries_hash[1]["name"],
street: #breweries_hash[3]["street"],
city: #breweries_hash[4]["city"],
phone: #breweries_hash[10]["phone"],
website_url: #breweries_hash[11]["website_url"]
}
Breweries::HoppyCode.new(breweries_obj)
end
end
end
You need to split the string you capture using gets with a character. You should ask for it in your message, normally that would be a comma, possibly surrounded by spaces.
I extracted the problem in a simplified script so that you can test it separately, which is always a good idea when solving a problem.
Mind the use of regular expressions between the // delimiters, and followed by the i flag to indicate that the comparison should be case-insensitive.
# what you would receive when you type this in the console following your message
# and captured by the gets, in this case brewerie 1 and 3
input = "1, 3"
#split by a comma preceded or followed or not by a space
breweries = input.split(/ *, */)
breweries.each do |brewerie|
if(brewerie.to_i > 0)
# #brewery = #objects[input.to_i - 1]
puts "displaying info about #{brewerie}"
elsif brewerie[/quit/i]
# quit
elsif brewerie[/menu/i]
# start
else
puts "Ooops, please try again to get more info:"
# display_info
end
end
Which returns:
displaying info about 1
displaying info about 3
From what I understand, You are asking the user to pick a brewery from a list of breweries. When they pick one, you show its info to them. What you could do instead is display a list of cities and let them pick a city and select all elements of the #objects where the city matches
def display_info
arr_of_cities = []
#objects.each{|element| arr_of_cities.push(element.city)}
arr_of_cities.each.with_index(1) {|city, index| puts "#{index}.#{city}"}
puts "Please make a selection by index number for more information:"
puts "****************************************************"
puts "Type Quit to end. Type Menu to try another location."
input = gets.strip.downcase
arr_of_breweries = #objects.where(city:arr_of_cities[input.to_i- 1])
if(input.to_i > 0)
arr_of_breweries.each.with_index(1) do |brewery,index|
puts "#{index}"
puts "name: #{#brewery.name}"
puts "street: #{#brewery.street}"
puts "city: #{#brewery.city}"
puts "phone: #{#brewery.phone}"
puts "website_url: #{#brewery.website_url}"
end
display_info
elsif (input == "quit")
quit
elsif (input == "menu")
start
else
puts "Ooops, please try again to get more info:"
display_info
end
end
Hopefully that helps. I haven't used ruby in a while so my syntax might be off a bit.

I trying to make a code that gives the user a personal number after they have made an user

Here is my ruby code. When you run it and you press 1 it will ask you for name and birth of date. I want to give the user a personal number after he is finished typing name and birth date. Futhermore I would be great to search for the users number to find them in the file. Hope someone can help!
I have written #HELP HERE were i need help. The code works fine, but I dont know how to code my problem...
file = File.new("Capgemini.txt", "a") #load information on startup, and create the file
class Customer # Making a class for the whole code to call it up later in the code
def new_custom
er # The costumer method
prompt = "> " #creating a class for prompt here, since I use it multiple times
puts"Full name of the person?"
print prompt
#name = gets.chomp.upcase #A global variabel which i can use outside the class
if File.read("Capgemini.txt").include?(#name) #so you don't register the same name, twice
puts"This name is already stored. Returning you to the main menu."
puts "_____________________________________________"
else
#puts"What is your employee number?"
#print prompt
##number = gets.chomp #Global
puts"Date of birth? (DD/MM/YYYY)"
print prompt
#birth = gets.chomp #Global
puts"Thanks for the input."
puts "_____________________________________________"
puts"Is this information correct? " #Giving the user all the information back to check for mistakes, etc.
puts ("Name: #{#name} Number: #{#number} Date of birth: #{#birth}")
puts "_____________________________________________"
puts "Yes or No?"
print prompt
while user_input = gets.chomp.upcase #loop while getting user input
case user_input
when "YES"
file = File.new("Capgemini.txt", "a")
file.puts("#{#name}, Number: #{#number}, Date of birth: #{#birth}") #puts the information into the textfile, separeted by commas
file.close
#NEED HELP HERE
number = File.readlines('Capgemini.txt')
puts "_____________________________________________"
puts
puts "Your employee number: "
puts "_____________________________________________"
#NEED HELP OVER HERE^
puts
puts "The information has now been stored in the Capgemini.txt file."
puts "_____________________________________________"
break # make sure to break so you don't ask again
when "NO"
puts "The information has not been stored. Returning you to the main menu."
puts "_____________________________________________"
break # and again
else
puts "Please either write 'Yes' or 'No'"
print prompt # print the prompt, so the user knows to re-enter input
end
end
end
end
def search_customer(search)
keyword = File.readlines('Capgemini.txt') #converting all the lines into indexes in an Array
matches = keyword.select { |name| name[/#{search}/] } #
if File.read("Capgemini.txt").include?(search) #An if statement that will print the results if the textfile matches the keyword
puts "_____________________________________________"
puts ("Search results including the word/number/birth " + search + ":")
puts "_____________________________________________"
puts matches
puts "_____________________________________________"
else #If not it will give the user feedback that its not there
puts "_____________________________________________"
puts ("Sorry, we couldnt find #{search} in the textfile.")
puts "_____________________________________________"
end
end
def all_customers
f = File.new("Capgemini.txt","r")
while !(f.eof?)
line = f.gets()
puts line
end
end
def delete_customer
puts("What customer do you want to delete?")
print("> ")
keyword = gets.chomp.upcase
txt_file = File.readlines('Capgemini.txt')
matches = txt_file.select { |name| name[/#{keyword}/] }
search_results = matches.length
if search_results > 1
puts "_____________________________________________"
puts "The name you entered gave these outputs:"
puts ""
puts matches
puts ""
puts "Please specify the name better, as we only allow one person to be deleted at the time. \nReturning you to the main menu."
puts "_____________________________________________"
else
if File.read("Capgemini.txt").include?(keyword) #An if statement that will print the results if the textfile matches the person
puts "_____________________________________________"
puts ("Is this the person you want to delete?")
puts matches
puts "_____________________________________________"
puts "Yes or No?"
print "> "
while user_input = gets.chomp.upcase # loop while getting user input
case user_input
when "YES"
no_matches = txt_file.reject { |name| name[/#{keyword}/] }
File.open('Capgemini.txt','w+'){|out| out.puts no_matches}
puts"User has been deleted. Returning you to the main menu."
puts "_____________________________________________"
break # make sure to break so you don't ask again
when "NO"
puts "User will not be deleted. Returning you to the main menu."
puts "_____________________________________________"
break # and again
else
puts "Please either write 'Yes' or 'No'"
print "> " # print the prompt, so the user knows to re-enter input
end
end
puts "_____________________________________________"
else #If not it will give the user feedback that its not there
puts "_____________________________________________"
puts ("Sorry, we couldnt find #{keyword} in the textfile.")
puts "_____________________________________________"
end
end
end
end
customer = Customer.new
require 'io/console'
select = 0
prompt = "> "
puts
puts
puts "Welcome to Capgemini Sogeti Denmark"
puts "_____________________________________________"
loop do (select != 7)
puts
puts("Press 1 to register a new user.\nPress 2 to search for a employee or keyword within the textfile.\nPress 3 to show all customers.\nPress 4 to delete a customer.\nPress 5 to exit.")
puts "_____________________________________________"
select = STDIN.getch.to_i
if(select == 1)
customer.new_customer
elsif(select == 2)
puts("What customer/keyword do you want to search for?") #You can search for a keyword, like forexample 'Manzur' which will prompt you back with every user names Manzur
print prompt
customer.search_customer(gets.chomp.upcase)
elsif(select == 3)
customer.all_customers
puts "_____________________________________________"
elsif(select == 4)
customer.delete_customer
elsif(select == 5)
puts
puts "The application will now exit."
puts "_____________________________________________"
break
else
puts"Invalid input. Please try again."
puts "_____________________________________________"
end
end
I am not sure how you want the numbers generated, but something like this could work.
This will always give you the highest number from your text file, and add 1 to it.
Keep in mind this method will be slow with a rather large amount of employees.
if File.exist?('Capgemini.txt')
number = File.readlines('Capgemini.txt')
#number = 1
number.each do |x|
customer = x.split(',')
customer_number = customer[1].gsub('Number: ', '').to_i
if customer_number >= #number
#number = customer_number + 1
end
end
else
#number = 1
end
Output:
BOB ROSS, Number: 1, Date of birth: 07/07/2007
WILL SMITH, Number: 2, Date of birth: 08/08/2008
JIM BOB, Number: 3, Date of birth: 09/09/2009
You can also use a similar method for searching through an array:
number = File.readlines('Capgemini.txt')
number.each do |x|
customer = x.split(',')
customer_name = customer[0]
customer_number = customer[1].gsub('Number: ', '').to_i
customer_bday = customer[2].gsub('Date of birth: ', '')
if customer_name == some_variable
puts x
end
end
There is a lot to say about this code (yours and mine). Run Ruby with the -w option to display unused variables, it points to possible mistakes like :
$ ruby -w t_op.rb
t_op.rb:180: warning: mismatched indentations at 'end' with 'class' at 3
t_op.rb:191: warning: possibly useless use of != in void context
t_op.rb:1: warning: assigned but unused variable - file
There are a lot of File.read, I have replaced them by an IO.readlines which creates an array of lines (OK for files which are not Gigabytes big). It also allows to store user numbers.
As always in Ruby, there are many ways to do the same thing.
require 'io/console'
class Customer
attr_reader :file
def initialize(p_file_name)
#file_name = p_file_name
refresh
#next_number = #numbers.max + 1
end
def refresh
#lines = IO.readlines(#file_name) # load information on startup
#numbers = []
#names = #lines.collect do | line |
# the line has the format : <name>, Number: <number>, Date of birth: <birth>
idxn = line.index(', Number')
idxd = line.index(', Date')
#numbers << line[idxn + 10...idxd].to_i
line[0...idxn]
end
end
def new_customer
prompt = "> " # creating a local variable for prompt, since I use it multiple times
puts 'Full name of the person ?'
print prompt
name = gets.chomp.upcase
if #names.include?(name) #so you don't register the same name, twice
then
puts_underlined 'This name is already stored. Returning you to the main menu.'
else
puts 'Date of birth? (DD/MM/YYYY)'
print prompt
birth = gets.chomp # TODO check validity
puts_underlined 'Thanks for the input.'
puts 'Is this information correct ?' # Giving the user all the information back to check for mistakes, etc.
puts_underlined "Name: #{name} Number: #{#next_number} Date of birth: #{birth}"
puts 'Y(es) or N(o)'
print prompt
while user_input = gets.chomp.upcase #loop while getting user input
case user_input[0]
when 'Y'
line = "#{name}, Number: #{#next_number}, Date of birth: #{birth}"
#next_number +=1
#lines << line
File.open(#file_name, 'a') do | file | # open the file for append, ensure it will be closed by the end of the block
file.puts line # puts the information into the textfile, separeted by commas
end
puts
puts_underlined "The information has now been stored in the #{#file_name} file."
break # make sure to break so you don't ask again
when 'N'
puts_underlined 'The information has not been stored. Returning you to the main menu.'
break # and again
else
puts 'Please either write Y(es) or N(o)'
print prompt # print the prompt, so the user knows to re-enter input
end
end
end
end # new_customer
def search_customer(search)
matches = #lines.grep(/#{search}/)
unless matches.empty? # An if statement that will print the results if the textfile matches the keyword
puts_underlined()
puts_underlined "Search results including the word/number/birth #{search} :"
puts matches
puts_underlined()
else # If not it will give the user feedback that it's not there
puts_underlined()
puts_underlined "Sorry, we couldnt find #{search} in the text file."
end
end
def search_customer_number(search)
index = #numbers.index(search.to_i)
if index
then # found, print the user
puts_underlined()
puts_underlined "This is the user number #{search} :"
puts #lines[index]
puts_underlined()
else # not found, it will give the user feedback that it's not there
puts_underlined()
puts_underlined "Sorry, we couldnt find the user #{search}."
end
end
def all_customers
puts #lines
end
def delete_customer
puts 'Which customer do you want to delete ?'
print '> '
keyword = gets.chomp.upcase
matches = #lines.grep(/#{keyword}/)
case matches.size
when 0 # not found, give the user feedback that it's not there
puts_underlined()
puts_underlined "Sorry, we couldnt find #{keyword} in the textfile."
when 1 # print the results if the textfile matches the person
puts_underlined()
puts 'Is this the person you want to delete ?'
puts_underlined matches
puts 'Yes or No?'
print '> '
while user_input = gets.chomp.upcase # loop while getting user input
case user_input
when 'YES'
no_matches = #lines.reject { | line | line[/#{keyword}/] }
File.open(#file_name, 'w+') { | out | out.puts no_matches }
refresh
puts_underlined 'User has been deleted. Returning you to the main menu.'
break # make sure to break so you don't ask again
when 'NO'
puts_underlined 'User will not be deleted. Returning you to the main menu.'
break # and again
else
puts "Please either write 'Yes' or 'No'"
print '> ' # print the prompt, so the user knows to re-enter input
end
end
else
puts_underlined()
puts 'The name you entered gave these outputs:'
puts
puts matches
puts
puts_underlined "Please specify the name better, as we only allow one person to be deleted at the time. \nReturning you to the main menu."
end
end # delete_customer
end # class Customer
def puts_underlined(p_text = nil)
puts p_text if p_text
puts '_____________________________________________'
end
file_name = 'Capgemini.txt'
customer = Customer.new(file_name)
prompt = "> "
puts
puts_underlined 'Welcome to Capgemini Sogeti Denmark'
loop do
puts
puts_underlined "Press 1 to register a new user.\nPress 2 to search for a employee.\nPress 3 to search for a keyword within the textfile.\nPress 4 to show all customers.\nPress 5 to delete a customer.\nPress 6 to exit."
select = STDIN.getch.to_i
case select
when 1
customer.new_customer
when 2
puts 'Which customer number do you want to search for ?'
print prompt
customer.search_customer_number(gets.chomp.upcase)
when 3
puts 'What keyword do you want to search for ?' # You can search for a keyword, like for example 'Manzur' which will prompt you back with every user names Manzur
print prompt
customer.search_customer(gets.chomp.upcase)
when 4
customer.all_customers
puts_underlined()
when 5
customer.delete_customer
when 6
puts
puts_underlined 'The application will now exit.'
break
else
puts_underlined 'Invalid input. Please try again.'
end
end

Ruby: 'gets' method called inside a method saves Nil instead of Input

Ok guys, this in a Dungeon Text Adventure project that runs on terminal.
When user says he wants to "go north" it splits the string: first word checks for method and second word for parameter. That happens someplace else, i copy pasted the 2 methods that are giving me the following problem:
When it calls go(north) and north isn't a valid connection, it shows the options and asks user for direction again, the input the user enters at that moment is stored as Nil for some reason.
Why?? I also tried STDIN.gets.chomp.downcase! and had same Nil results
Here's the code:
def find_room_in_direction(direction)
##-> if room connects with other on that direction, returns connection
if find_room_in_dungeon(#player.location).connections.include?(direction.to_sym)
return find_room_in_dungeon(#player.location).connections[direction.to_sym]
##-> if direction connection is not found,
##-> show possible connections & return trigger to ask again inside go()
elsif !find_room_in_dungeon(#player.location).connections.include?(direction.to_sym)
puts "I don't see any #{direction}..."
puts "This room only connects #{(find_room_in_dungeon(#player.location)).connections.keys.join(', ')}"
puts "Where should we go?"
return :redo
end
end
def go(direction)
current_direction = #player.location
new_direction = find_room_in_direction(direction)
##-> if REDO trigger received, ask for new direction & try again
if new_direction == :redo
puts "REDOING DIRECTION"
##-> HERE IS THE PROBLEM:
##-> this does ask for input
new_direction = gets.chomp.downcase!
##-> but it saves Nil instead of the input, so that puts shows ''
puts "#{new_direction}"
##-> so this call trows an error: cant call method to Nil
new_direction = find_room_in_direction(new_direction)
##-> if user entered valid direction from start, the following would run
elsif new_direction != :redo && current_direction != new_direction
#player.location = new_direction
puts "You go #{direction},"
puts "and enter #{show_current_description}"
end
end
Any suggestions?
Thanks!
You are using downcase! instead of downcase. downcase! changes a string in-place and returns nil if there were no changes (which is what is happening here).
str = "teSt"
puts str.downcase # test
puts str # teSt
str.downcase!
puts str # test
See the documentation for downcase!
Just bang chomp. As for downcase there are two variants - chomp and chomp!

return result back to view

i am trying to keep all my logic out of views, and have come up with the following piece of code, the though im having is that it isnt returning the actual score value, it just returns if it was a Win, lost or tie
def find_result(schedule)
return "not required" if schedule.event != '1' or schedule.time >= Time.now
if schedule.for.nil? or schedule.against.nil?
"Not Entered"
else
tie = '<b>T</b> '
tie << schedule.for.to_i
tie << ' - '
tie << schedule.against.to_i
win = '<b>W</b> '
win << schedule.for.to_i
win << ' - '
win << schedule.against.to_i
return raw tie if schedule.for.to_i == schedule.against.to_i
schedule.for.to_i > schedule.against.to_i ? (raw win) : "Lost"
end
end
Don't use << with an integer. See the docs:
http://www.ruby-doc.org/core-1.9.3/String.html#method-i-3C-3C
It's probably turning your win/loss numbers into characters that aren't showing up in the HTML.
Use a formatter or something, or perhaps just to_s rather than to_i when appending the numbers.
Example using string format (untested):
def find_result(schedule)
return "not required" if schedule.event != '1' or schedule.time >= Time.now
if schedule.for.nil? or schedule.against.nil?
"Not Entered"
elsif schedule.for.to_i < schedule.against.to_i
"Lost"
else
raw "<b>%s</b> %d - %d" % [
schedule.for.to_i == schedule.against.to_i ? 'T' : 'W',
schedule.against.to_i,
schedule.for.to_i
]
end
Edit: Refactor
Keeping logic out of the views is good, but it would be even more appropriate to
move some of this to the model, namely the result of the schedule (not entered,
win, loss, tie)
In the example I'll make a simple inner class which encapsulates that logic, which
the Schedule makes use of to know its own result. You could do this any number of ways
though (e.g. a module versus a class, or methods directly on Schedule)
I'll then demonstrate how you might use the new schedule in your helper using the logic provided, or simply querying for the result itself and using it as a key for a translation lookup (I18n).
Note this is untested and a little bit pseudo-codey (I'm not using any I18n library in particular, just guessing at methods and translation formatting). But it should work with some tweaking, or at least give you an idea of another way of doing things.
class Schedule
# The schedule jus instantiates a result object when you ask for one.
# For convenience the result's to_s is it's value, e.g. "win"
def result
Result.new(self.for, self.against)
end
# delegate methods querying the result
delegate :win?, :loss?, :tie?, :not_entered?, :to => :result
class Result
Values = %(win loss tie not_entered)
Win = Values[0]
Loss = Values[1]
Tie = Values[2]
NotEntered = Values[3]
attr_reader :for, :against
def initialize(_for, against)
#for = _for
#against = against
end
def value
return NotEntered unless [#for, #against].all?
case v = #for - #against
when v.zero? then Tie
when v > 0 then Win
else Loss
end
end
alias :to_s :value
def not_entered?; self.value == NotEntered end
def win?; self.value == Win end
def loss?; self.value == Loss end
def tie?; self.value == Tie end
end
end
# then in your helper, something like
def find_result(schedule)
# you'd want to refactor this requirement part too
return "not required" if schedule.event != '1' or schedule.time >= Time.now
# Now you could do it essentially the way you had, with ifs or a
# case statement or what have you, but the logic for the result is kept
# where it belongs, on the class.
if schedule.not_entered?
"Not Entered"
elsif schedule.loss?
"Loss"
else
prefix = schedule.win? ? "W" : "T"
raw "<b>%s</b> %d - %d" % [prefix, schedule.for, schedule.against]
end
# OR you could use some kind of translation library using the `value`
# returned by the result. Something like:
key = ["schedule", schedule.outcome.value].join(".")
raw I18n.translate(key, {:for => schedule.for, :against => schedule.against})
end
# if you used the latter, it would lookup the translation in some other place,
# e.g. some config JSON, which might look like this (more or less, and
# depending on the lib you use):
{
"schedule": {
"win": "<b>W</b> {{for}} - {{against}}",
"tie": "<b>T</b> {{for}} - {{against}}",
"loss": "Loss",
"not_entered": "Not Entered"
}
}
# The translation has a few advantages. It would allow you to sub in other
# languages, but also, it conveniently keeps all of the app's text in one
# place, if you stick to using it.

Resources