Skip to content

Commit

Permalink
UNITS!
Browse files Browse the repository at this point in the history
Resolves #56
  • Loading branch information
pikesley committed Jan 31, 2016
1 parent 488f997 commit 06d5cf7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
8 changes: 8 additions & 0 deletions app/models/carbohydrate_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ def self.short_name
'Carbs'
end

def self.units
{
full: 'Grams',
short: 'g',
applies_to: :weight
}
end

def self.fields
[
'weight',
Expand Down
8 changes: 8 additions & 0 deletions app/models/glucose_measurement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ def self.short_name
'Glucose'
end

def self.units
{
full: 'millimoles per Litre',
short: 'mmol/L',
applies_to: :value
}
end

def self.fields
[
'value'
Expand Down
8 changes: 8 additions & 0 deletions app/models/medication_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ def self.short_name
'Meds'
end

def self.units
{
full: 'Insulin units',
short: 'u',
applies_to: :dose
}
end

def self.insulin_types
[
'humalog',
Expand Down
8 changes: 8 additions & 0 deletions app/models/physical_exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ def self.short_name
'Exercise'
end

def self.units
{
full: 'Minutes',
short: 'mins',
applies_to: :duration
}
end

def self.fields
[
'duration',
Expand Down
9 changes: 8 additions & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<tr>
<td>
<%= link_to value.datetime.strftime('%H:%M'),
send("edit_#{value.class.name.underscore}_path".to_sym, value) %>
send("edit_#{value.class.name.underscore}_path".to_sym, value),
title: 'Edit this metric'
%>
</td>
<td>
<%= class_name(value).short_name %>
Expand All @@ -27,6 +29,11 @@
<% class_name(value).fields.each do |field| %>
<td class='<%= "#{value.class.name.underscore.gsub('_', '-')}-#{field}" %>'>
<%= value.send(field) %>
<% if value.class.units[:applies_to] == field.to_sym %>
<span data-toggle='tooltip' data-placement='top' title='<%= value.send(field) %> <%= value.class.units[:full] %>'>
<%= value.class.units[:short] %>
</span>
<% end %>
</td>
<% count += 1 %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/medication_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
select 'humalog', from: 'Insulin'
click_button 'Add'

expect(page.all('td').map { |cell| cell.text }).to eq ['09:00', 'Meds', '10.5', 'humalog']
expect(page.all('td').map { |cell| cell.text }).to eq ['09:00', 'Meds', '10.5 u', 'humalog']

visit new_medication_event_url(as: user)
fill_in 'Date and time', with: Time.now - 86400
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/welcome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
it 'has a table of datas' do
visit root_path(as: user)
within 'table' do
expect(page).to have_content '09:30 Carbs 70.0 pasta bolognese'
expect(page).to have_content '09:00 Glucose 6.0'
expect(page).to have_content '08:30 Meds 10.0 humalog'
expect(page).to have_content '08:00 Glucose 6.0'
expect(page).to have_content '09:30 Carbs 70.0 g pasta bolognese'
expect(page).to have_content '09:00 Glucose 6.0 mmol/L'
expect(page).to have_content '08:30 Meds 10.0 u humalog'
expect(page).to have_content '08:00 Glucose 6.0 mmol/L'
end
end
end
Expand Down

0 comments on commit 06d5cf7

Please sign in to comment.